This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Date validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date validation" Watch "Date validation" New topic
Author

Date validation

Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 230
Is there any REAL date validator-library available?

SimpleDateFormat (ok, it's just a formatter) is just too crippled. Even with setLenient(true); it passes ex: 11.12.2009kjdsjdsjjds.


SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

You can use the method with the ParsePosition, then check if the ParsePosition is at the end of the string.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 230
Thanks!
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3003
    
    9
Jari Timonen wrote:Is there any REAL date validator-library available?

SimpleDateFormat (ok, it's just a formatter) is just too crippled. Even with setLenient(true); it passes ex: 11.12.2009kjdsjdsjjds.

If you want stricter validation, you probably want setLenient(false), not true. It will still pass the example you give here if you use parse(String), since that's part of the method description. But setLenient(false) will at least make other aspects of the validation stricter.
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 230
REAL validation
 
 
subject: Date validation
 
Similar Threads
WA #1.....word association
Date or Timestamp?
Another format check :P
How to Ping Multiple Servers
Displaying the Date - Issue