Created
August 7, 2013 15:03
-
-
Save webdevbrian/6174838 to your computer and use it in GitHub Desktop.
Age checker validation for jQuery.Validate()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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