John de Michele wrote:Mel:
This looks like a job for regular expressions.
John.
Thanks John! I feel
you should be wearing a cape. The wheels are definitely turning!!! Now let me ask you this or anyone who is reading... the problem states that the user inputs the SSN number... and it also says to assume that 'D' is an interger. I am not sure if he was hinting at something there... is there a way to recognize the 'D' as any integer?
As an example: "434-23-4953".matches("DDD-DD-DDDD"); where 'D' can be any integer. Is there a method that will do that? or is there another way to approach it!?
***** Thinking to myself ***** wait... what if i used the replaceAll method to replace any integer to the letter 'D' and then use the matches method to to compare both strings....
HA!!! I DID IT !!! lol... wow... that was pretty easy!! thanks again John!!!
Problem... I am not seeing whats wrong here. if i put in a set string, it returns true. however from the user's input, it returns false. ummm... why?
Assume the user input 234-23-4224:
ssn.replaceAll("[0123456789]", "D");
System.out.println(ssn.matches("DDD-DD-DDDD"));
FALSE
String
test = "123-34-2345".replaceAll("[0123456789]", "D");
System.out.println(test.matches("DDD-DD-DDDD"));
TRUE
UPDATE: Got it to work!