The code snippet below can be used for data validation.

Java Code:
public static boolean validateDate(String dateStr, 
                 boolean allowPast, String formatStr)
if (formatStr == null) return false; 
// or throw some kinda exception, possibly a InvalidArgumentException
SimpleDateFormat df = new SimpleDateFormat(formatStr);
Date testDate = null;
testDate = df.parse(dateStr);
catch (ParseException e)
// invalid date format
return false;
if (!allowPast)
// initialise the calendar to midnight to prevent
// the current day from being rejected
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
if (cal.getTime().after(testDate)) return false;
// now test for legal values of parameters
if (!df.format(testDate).equals(dateStr)) return false;
return true;