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

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -