Created
July 18, 2011 16:16
-
-
Save neilmiddleton/1089985 to your computer and use it in GitHub Desktop.
jQuery validation helpers
This file contains hidden or 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
jQuery.validator.addMethod "min_age", (value, element) -> | |
date = value.split '-' | |
dob = new Date date[0], date[1], date[2] | |
_today = new Date() | |
_18_years_ago = new Date _today.getYear() - 18, _today.getMonth(), _today.getDay() | |
return dob < _18_years_ago | |
, "You must be over 18 years of age to use Nutmeg" | |
jQuery.validator.addMethod "max_age", (value, element) -> | |
date = value.split '-' | |
dob = new Date date[0], date[1], date[2] | |
_today = new Date() | |
_100_years_ago = new Date _today.getYear() - 100, _today.getMonth(), _today.getDay() | |
return dob > _100_years_ago | |
, "You must be under 100 years of age to use Nutmeg" | |
jQuery.validator.addMethod "ni_number", (value, element) -> | |
return /^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z] ?([0-9]{2} ?){3} ?[ABCD ]?$/.test(value) | |
, "You must supply a valid National Insurance Number" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment