It's not a secret anymore!
The moose likes Struts and the fly likes Date validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Date validation" Watch "Date validation" New topic

Date validation

Shein Zeya

Joined: Jun 04, 2008
Posts: 10
I am trying a Struts Project in which validation of date is included.There..I have to validate the input date whether it is valid or not.If the date is not in the past but in the future..that's invalid.

In the process of trying I found some difficulties.
In my program....whatever user entered..just appear the invalid Date error message.Here's my codes

String userDob=aForm.getDob();

//here Date currentDate = new Date();
java.util.Date currentDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

Calendar udob= new GregorianCalendar();
Calendar cdate = new GregorianCalendar();

try { udob.setTime((Date) formatter.parse(userDob));
catch (ParseException e)
//DefaultLogger.debug("AValidator","DOB is Future Date"+ udob);
DefaultLogger.debug("this", "DOB is Future Date" + aForm.getDob());
errors.add("dob", new ActionError("error.string.dobinvalid", "1", "20"));

return errors;

Please do help me....Thank you
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If all you're doing is comparing one date to another to see which is later, you don't need to use a java.util.Calendar. Just use a java.util.Date. Example:

Consultant, Sima Solutions
I agree. Here's the link:
subject: Date validation
It's not a secret anymore!