Jiggmin's Village

Full Version: coding help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
http://prntscr.com/s7l0rf

got a problem with lines 31-36

its supposed to catch the exception if there is a non-number character in the string
but it doesnt catch it if its the last 3 characters i.e "123-45-7abc" is apparently a valid SSN format according to my code (but its not supposed to be)
charAt equates to an integer (ASCII codes). See here for more information: https://www.cs.cmu.edu/~pattis/15-1XX/co...ascii.html.

Therefore, parseInt() won't throw an error. If you want to test if it's not a number, try this:

Code:
char thisChar = ssn.charAt(i);
if (thisChar < 48 || thisChar > 57) {
    // handle error
}