I am trying to check a date for validation. Below is my code. When I check for the date 12/12/2014XYZ, SimpleDateFormat.parse does not throw exception. With other invalid dates like 13/13/2014 it is throwing exception.
public class DateCheck{
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(false);
try {
sdf.parse("12/31/2014XYZ");
System.out.println("Valid Date");
} catch (Exception e) {
System.out.println("Invalid Date");
}
}
}
I googled a lot but could not find the proper solution.