I was trying to check if a date(in MM/dd/yyyy format) is a valid date in javascript. But while passing a wrong date, it is not able to distinguish. I was using the below logic to check if it is a valid date or not.
var dt = document.forms["registerForm"]["dateOfBirth"].value;
try{
var d = new Date(dt);
alert(d);
}catch(err){
alert("not a valid date");
return false;
}
while the dateOfBirth is "02/47/2016" it is not going to the exception block, rather it is interpreting "02/47/2016" as Fri Mar 18 2016 00:00:00 GMT+0530 (IST). But when i tried with "02/03/2016" it is interpreting correctly as Wed Feb 03 2016 00:00:00 GMT+0530 (IST).