Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Check for Valid Date  RSS feed

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to check if adate entered is valid. I tried using DateFormat.parse. But when I enter 10/39/05 it accepts it and parses it into 11/08/05.

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String historyDate = dateField.getText();
try {
df.parse(historyDate);
} catch (ParseException pe) {
System.err.println("Invalid Date: " + dateField.getText());
return;
}

Any thoughts would be appreciated. Thanks, Lisa
 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing specific about GUI in this question, so I'll move it to Java In General (Intermediate)
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that the ParseException will report the kind of error you are looking for. It only deals with parsing the String. It does not deal with the contents of what is parsed.
 
Sheriff
Posts: 23874
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try addingIt's not clear to me why "lenient" date parsing (the situation you described there) should even be an option, let alone why it should be the default option. The designers of Java seem to have been smoking some strange substances when they designed the parts dealing with dates.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!