Posted By

adambundy on 12/15/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

adambundy


Validate a date of birth using jQuery


 / Published in: jQuery
 

courtesy Jean-Baptiste Jung

  1. $("#lda-form").submit(function(){
  2. var day = $("#day").val();
  3. var month = $("#month").val();
  4. var year = $("#year").val();
  5. var age = 18;
  6. var mydate = new Date();
  7. mydate.setFullYear(year, month-1, day);
  8.  
  9. var currdate = new Date();
  10. currdate.setFullYear(currdate.getFullYear() - age);
  11. if ((currdate - mydate) < 0){
  12. alert("Sorry, only persons over the age of " + age + " may enter this site");
  13. return false;
  14. }
  15. return true;
  16. });

Report this snippet  

You need to login to post a comment.