Last active
February 18, 2020 15:28
-
-
Save leowebguy/4074cfe53a34bce73b98940f839ecfdb to your computer and use it in GitHub Desktop.
jquery validade custom 18+
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.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