We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

damarev on 07/17/06


Tagged


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

meth
jkochis


checkDate


Published in: JavaScript 


  1. function checkDate(name){
  2. var x = document.forms[0].elements;
  3. var day = parseInt(x[name+"_dia"].options[x[name+"_dia"].selectedIndex].value);
  4. var month = parseInt(x[name+"_mes"].options[x[name+"_mes"].selectedIndex].value);
  5. var year = parseInt(x[name+"_anio"].options[x[name+"_anio"].selectedIndex].value);
  6.  
  7. if (!day || !month || !year)
  8. return false;
  9.  
  10. if (year/4 == parseInt(year/4))
  11. monthLength[1] = 29;
  12.  
  13. if (day > monthLength[month-1])
  14. return false;
  15.  
  16. monthLength[1] = 28;
  17.  
  18. var now = new Date();
  19. now = now.getTime(); //NN3
  20.  
  21. var dateToCheck = new Date();
  22. dateToCheck.setYear(year);
  23. dateToCheck.setMonth(month-1);
  24. dateToCheck.setDate(day);
  25. var checkDate = dateToCheck.getTime();
  26.  
  27. var futureDate = (now < checkDate);
  28. var pastDate = (now > checkDate);
  29.  
  30. return true;
  31. }

Report this snippet 

You need to login to post a comment.