/ Published in: JavaScript
                    
                                        
How would you validate the number of days in a given month?
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
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
}
}
URL: http://stackoverflow.com/questions/1433030/validate-number-of-days-in-a-given-month
Comments
 Subscribe to comments
                    Subscribe to comments
                
                