• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Date validation

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
can someone helpe me , is there any good way of validating an input date string.

Even after setting lenient as false in SimpleDateFormat , for the patter mm/dd/yyyy its validating this date fine : 10/02/23a0 or 10/2/23445
I have seen apache common's date validator , but in version 1.4 or less it doenst not have validdate method with leneincy option.

Thanks
Sudharshan
 
author
Posts: 23836
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you provide some code that proves this? I find what you describe as being hard to believe.

Henry
 
Henry Wong
author
Posts: 23836
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


And BTW, "mm" means minutes, not months.

Henry
 
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a bug in the parsing, it's a design feature*. The reason behind this is that you can parse one String using multiple formats. For instance, first a Date, then some String, then a number, then another String, then another format. By using a ParsePosition object you can chain this formatting.

Fortunately, that very same class can help us out here. By using the alternative parse method, you can get the location where parsing stopped:



* Well, maybe it is a bug. The parse(String) method uses the above parse method internally, but it only throws a ParseException if the Date is null. It doesn't have the comparison between the parse position and the String length. It perhaps should have it, but I doubt it will be added after all this time. That's why I have a utility method for parsing strictly like the above.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!