I'm trying to validate a registration form with jQuery Validate plugin. One of the requirements is that the select field must select a persons minimum age (13).
How would i do that? I can figure out the minimum year but i can't figure out how jquery validate picks a range described here: http://docs.jquery.com/Plugins/Validation/Methods/min#value
Form markup:
<form>
...
<select id="yearborn" name="yearborn">
<option value="" disabled="disabled">Choose an option</option>
<option value="1901" >1901</option>
<option value="1902" >1902</option>
<option value="1903" >1903</option>
...
<option value="2011" >2011</option>
</select>
</form>
Then the attempted jQuery form validation:
jQuery('#register-form')
.validate({
submitHandler: function(form) {
form.submit();
},
rules: {
yearborn: {
required: true,
min: 13
}
}
});
Any ideas? I looked over this thread but it's related to requiring input:
- jQuery Validate Required Select
- jQuery Validate (Date Rang开发者_如何学Goe) - Used a different field
Why even give the user the option to choose an invalid year ?
If you can control the server-side that prints the select-box, just print the allowed years (this year - 13),
otherwise min should be a year, not an age ...
min 1998 == 2011-13 (this year - 13)
精彩评论