Validating strings
Hi! I'm doing a project for my management of information systems class. My professor wants me to validate a date using the method "matches()."
Update:
I got the code to work! Yay. I was playing around with the parentethes and \\/ like someone suggested. Here's the new code:
He tried this code, but it doesn't work. He wants to students to make it work. :D
The date format should be in: mm/dd/yyyy as in: 01/31/2004.
This is almost the exact same code he gave us:
The problem (logic error) is with this line:
Update:
I got the code to work! Yay. I was playing around with the parentethes and \\/ like someone suggested. Here's the new code:
else if (!dateTextField.getText().matches(
"([0][1-9])|([1][0-2])\\/"
+ "([0][1-9]|[1-2][0-9]|[3][0-1])\\/"
//+ "([0][1-9])|([1-2][0-9])\\/"
+ "2004"))
He tried this code, but it doesn't work. He wants to students to make it work. :D
The date format should be in: mm/dd/yyyy as in: 01/31/2004.
This is almost the exact same code he gave us:
if ...
else if (!dateTextField.getText().matches(
"([0][1-9])|([1][0-2])\\/" // Digits for the days
+ "([0][1-9])|([1-2][0-9])|([3][0-1])\\/" // Month digits
+ "[2][0][0][4]")) // Year
else ...
The problem (logic error) is with this line:
"([0][1-9])|([1-2][0-9])|([3][0-1])\\/" // Month digits
([0][1-9]) works if I comment everything else on the line. If I add |([1-2][0-9])|([3][0-1])\\/ , the code doesn't work.
My professor didn't teach us how to use {} and \\d. I'm not sure how to use them in the code above.
The other lines work.
