java - Checking if characters in a string are digits, but with exceptions -
OK so I have this string SSN, and it is considered to be a social security number with the proper format. I have to check to ensure that there is no non-digit in the SSN except Dash. I have already made a loop that ensures that the dash is in the right place, but I'm not sure how can I check that there are non-digit characters without the unchecked dash. Is this a method that I can dash out this check?
This is my current code, I just do not know how- '(sorry, completely forgotten)
SSN is a string object that was entered by the user is.
for (int i = 0; i & lt; snn.length (); i ++) {If (Character.isDigit (ssn.charAt (i))}
Consider using regular expressions.
For example: < Public stable boolean is ValidSocialSecurityNumber (strings) {pattern p = Pattern.compile ("^ \ \ d {3} - \\ d {2} - \\ d {4} $") ; Mature M = P. MATTURE (return); MAMTech ();}
Comments
Post a Comment