Return to Snippet

Revision: 34762
at October 28, 2010 01:22 by 1man


Initial Code
//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
		}
	}
});

Initial URL
http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Initial Description
Useful snippet i found on a forum, use it to check to see if a user is old enough to submit a form.

Initial Title
Validate an age using jQuery Validator plug-in

Initial Tags
jquery

Initial Language
jQuery