Created
November 13, 2013 12:49
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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