isDateValid - Validate a date in javascript


/ Published in: JavaScript
Save to your folder(s)

A simple JS script to validate a date. It returns a boolean type (true | false)


Copy this code and paste it in your HTML
  1. /**
  2.  * Check if a date is valid
  3.  * @return bool
  4.  * @author Mardix
  5.  * @since: June 30 2009
  6.  */
  7. isDateValid = function(year,month,date){
  8.  
  9. if(year && month && date){
  10. if(month==2){
  11. if((year%4 == 0) && date>29)
  12. return false
  13. else if((year%4!=0) && date > 28)
  14. return false;
  15. }
  16.  
  17. if((month!=2 && month!=8) && ((month%2 != 1) && date>30))
  18. return false;
  19. else
  20. return true;
  21. }
  22.  
  23. else
  24. return false;
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.