Hi,
I am trying to check for MM /DD /YYYY.
currently my script fails when you enter 0 / 0 /0 or 00/00/0000. I am trying to check that the user is over 21 and must enter a valid two digit month, two digit day and 4 digit year.
Any suggestions?
$("#gate-box").submit(function() {
var day = $("#day").val();
var month = $("#month").val();
var year = $("#year").val();
var age = 21;
var mydate = new Date();
mydate.setFullYear(year, month - 1, day);
var currdate = new Date();
currdate.setFullYear(currdate.getFullYear() - age);
if ((currdate - mydate) < 0) {
$.msg("Sorry, you must be at least " + age + " to enter.");
return false;
}
else if (month > 12) {
$('#month').css({ 'border': '1px solid red' });
$.msg("Please enter a valid month.");
$('#month').focus();
return false;
}
else if (day > 31) {
$('#month').css({ 'border': 'none' });
$('#day').css({ 'border': '1px solid red' });
$.msg("Please enter a valid day.");
$('#day').focus();
return false;
}
else if (month.length === 0 || day.length === 0 || year.length === 0) {
$('#day').css({ 'border': 'none' });
$.msg("Please enter all fields.");
return false;
}
if ((currdate - mydate) > 0) {
$.colorbox.close()
$.setCookie('diageoagecheck', 'verified', { duration: 3 });
}
return false;
});