/ Published in: jQuery
Useful snippet i found on a forum, use it to check to see if a user is old enough to submit a form.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Legal age validator check $.validator.addMethod('check_date_of_birth', function(value, element) { var day = $("#dob_day").val(); var month = $("#dob_month").val(); var year = $("#dob_year").val(); var age = 18; var mydate = new Date(); mydate.setFullYear(year, month-1, day); var currdate = new Date(); currdate.setFullYear(currdate.getFullYear() - age); return (currdate - mydate < 0 ? false : true); }); //Usage $("#theform").validate({ rules: { dob_day: { check_date_of_birth: true, required: true } } });
URL: http://bassistance.de/jquery-plugins/jquery-plugin-validation/