I have three fields for date input - day, month, year. Once it is input, I should verify it. The following code is used:
$('#test').click(function(event) {
var daySelector = "#dd",
monthSelector = "#mm",
yearSelector = "#yyyy";
var day = $(daySelector).val() == "" ? 1 : parseInt($(daySelector).val(), 10);
var month = $(monthSelector).val() == "" ? 1 : parseInt($(monthSelector).val(), 10);
var year = parseInt($(yearSelector).val(), 10);
var date = new Date(year, month, day);
var result = !isNaN(date.getTime());
});
But it accepts (i.e. returns true
) wrong values like 33/55/2000. Where is my mistake?
Demo
I've tried another approach - it doesn't work well also.