Skip to content

Instantly share code, notes, and snippets.

@leowebguy
Last active February 18, 2020 15:28
Show Gist options
  • Save leowebguy/4074cfe53a34bce73b98940f839ecfdb to your computer and use it in GitHub Desktop.
Save leowebguy/4074cfe53a34bce73b98940f839ecfdb to your computer and use it in GitHub Desktop.
jquery validade custom 18+
$.validator.addMethod('eighteenOrOlder', function(v, el) {
var month = $('input[name="dobMonth"]').val();
var day = $('input[name="dobDay"]').val();
var year = $('input[name="dobYear"]').val();
var birthDate = new Date();
birthDate.setFullYear(year, month - 1, day);
var currDate = new Date();
currDate.setFullYear(currDate.getFullYear() - 18);
if ((currDate - birthDate) > 0) {
return true;
} else {
return false;
}
}, "You must be over 18 to be eligible to participate.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment