Posted By

mardix on 06/30/09


Tagged

date validate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mrsize
kitsched


isDateValid - Validate a date in javascript


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.