Hi, I am having a problem with the parse method in SimpleDateFormat. I would expect the code below to catch a ParseException since the String textToParse is not a valid date. However, an exception is not thrown and a Date is returned. I would like to use this code to validate user input. Any suggestions? Thanks!
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
If you look at the javadocs of the parse method, you'll see that it may not use all of the text supplied. That's what is happening here. I'm not sure if this can be influenced by a call to "setLenient(false)", but it's worth a shot. If that doesn't work I'd suggest a regular expression for validation.