Posted By

satie83 on 07/12/13


Tagged

javascript validation dates


Versions (?)

Javascript - Validate number of days in a given month


 / Published in: JavaScript
 

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?

  1. function validateDate( intDay, intMonth, intYear )
  2. {
  3. return intMonth >= 1 && intMonth <= 12 && intDay > 0 && intDay <= daysInMonth( intMonth, intYear );
  4. }
  5.  
  6. function daysInMonth( intMonth, intYear )
  7. {
  8. switch ( intMonth )
  9. {
  10. case 2:
  11. return (intYear % 4 == 0 && intYear % 100) || intYear % 400 == 0 ? 29 : 28;
  12. case 4:
  13. case 6:
  14. case 9:
  15. case 11:
  16. return 30;
  17. default :
  18. return 31
  19. }
  20. }

Report this snippet  

You need to login to post a comment.