If somehow you are trying to validate dates that involves 2 drop downs and the values in the drop down are set, you can do the following.
function validateDate(dateToCheck, selectedDay)
{
var totalMonthCount = 12;
var i = 1;
var isValid = true;
var monthToCheck = parseInt(dateToCheck.getMonth());
var yearToCheck = parseInt(dateToCheck.getFullYear());
if(selectedDay > 28)
{
if(monthToCheck == 2)
{
if(yearToCheck%4 == 0)
{
if(selectedDay > 29)
{
isValid = false;
}
}
else
{
isValid = false;
}
}
if((monthToCheck == 4) || (monthToCheck == 6) || (monthToCheck == 9) || (monthToCheck == 11))
{
if(selectedDay > 30)
{
isValid = false;
}
}
}
return isValid;
}
Subscribe to:
Post Comments (Atom)
does that work for day-light saving?
ReplyDeleteI am only validating the day, month and year.
ReplyDeleteNo time checking, unfortunately