Skip to content

Instantly share code, notes, and snippets.

@lerua83
Created November 13, 2013 12:49
Show Gist options
  • Save lerua83/7448539 to your computer and use it in GitHub Desktop.
Save lerua83/7448539 to your computer and use it in GitHub Desktop.
URL: http://stackoverflow.com/questions/1433030/validate-number-of-days-in-a-given-month How would you validate the number of days in a given month?
function validateDate( intDay, intMonth, intYear )
{
return intMonth >= 1 && intMonth <= 12 && intDay > 0 && intDay <= daysInMonth( intMonth, intYear );
}
function daysInMonth( intMonth, intYear )
{
switch ( intMonth )
{
case 2:
return (intYear % 4 === 0 && intYear % 100) || intYear % 400 === 0 ? 29 : 28;
case 4:
case 6:
case 9:
case 11:
return 30;
default :
return 31;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment