I get three variables through user input, which contains the year of the date, month, and day. I already checked if the month var from 1 to 12 exists, etc.
Now I want to check if this is a real date, and not a date that does not exist, for example, 06/31/2011.
My first idea was to create a new Date instance:
var year = 2011; var month = 5; // five because the months start with 0 in JavaScript - June var day = 31; var myDate = new Date(2011,5,31); console.log(myDate);
But myDate does not return false because it is not a valid date. Instead, it returns "Fri Jul 01 2011 [...]".
Any ideas how I can check for an invalid date?
source share