validating a text field that has date in the format mm/dd/yyyy

How can I validate a text field such that it should be in the format mm/dd/yyyy and it should not be greater that a particular date.for example the date I enter should not be greater than 01/01/2007
[212 byte] By [karan_Ka] at [2007-11-26 17:13:11]
# 1
Read the Date API. There's already a method that does this.
es5f2000a at 2007-7-8 23:41:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

What you can do is use the SimpleDateFormat class to try and parse the text date into a Date object like this:

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

Date mydate = sdf.parse(textdate);

if that fails than the date has the wrong format (you'll get a ParseException if I'm not mistaken).

The next step is to create a Date for 1/1/2007 and then do a date compare between your two dates. You can create a date yourself using the Calendar class.

gimbal2a at 2007-7-8 23:41:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...