Skip to content

Instantly share code, notes, and snippets.

@webdevbrian
Created August 7, 2013 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdevbrian/6174838 to your computer and use it in GitHub Desktop.
Save webdevbrian/6174838 to your computer and use it in GitHub Desktop.
Age checker validation for jQuery.Validate()
// Validator additional methods
$.validator.addMethod("check_date_of_birth", function(value, element) {
var day = $("#dobd").val();
var month = $("#dobm").val();
var year = $("#doby").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;
}, "You must be at least 18 years of age.");
// Usage
// to be added to your rules
dobd: {
check_date_of_birth: true,
required: true
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment