Validate a date of birth using jQuery


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

courtesy Jean-Baptiste Jung


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.