Return to Snippet

Revision: 64191
at July 12, 2013 19:08 by satie83


Initial Code
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
    }
}

Initial URL
http://stackoverflow.com/questions/1433030/validate-number-of-days-in-a-given-month

Initial Description
How would you validate the number of days in a given month?

Initial Title
Javascript - Validate number of days in a given month

Initial Tags
javascript, validation

Initial Language
JavaScript