coding help
#1
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)
Reply
#2
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
}


I post about the latest site updates on the Dev Log. If you have suggestions, feel free to post them here.
@Eternal and I pay for this site out of our own savings. Please donate to help keep Jiggmin's Village free for all.
The Following 1 User Says Thank You to bls1999 For This Useful Post:
  • JEEJAYEM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)