This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649
    
  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: 2982
    
    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
 
wood burning stoves
 
subject: Date validation
 
Similar Threads
Date or Timestamp?
WA #1.....word association
Another format check :P
How to Ping Multiple Servers
Displaying the Date - Issue