我正在使用jquery驗證來驗證我的表單之前提交,我如何驗證提交之前的選擇框值?jquery驗證插件,選擇值驗證
在上面的例子我想如果當前選擇的元素具有值==驗證失敗0
HTML
<form action="/foo" id="register_form" method="post">
<select id="city_select" name="city_id">
<option value="0">Select City</option>
<option value="4">New York</option>
<option value="24">Chicago</option>
<option value="25">Washington</option>
</select>
<input class="" id="username" name="username" type="text" /><br/>
<input class="" id="email" name="email" placeholder="Email" type="text" /><br/>
<input class="" id="password1" name="password1" type="password" />
<input class="" id="password2" name="password2" type="password" /><br/>
<input type="checkbox" value="1" name="terms_of_use" id="terms_of_use">
</form>
的Jquery /驗證
$('#register_form').validate({
onfocusout: function (element, event) {
},
rules : {
username: {
required: true
},
email: {
required: true,
email: true
},
terms_of_use: {
required: true
},
password1: {
required: true,
rangelength: [5, 50]
},
password2: {
required: true,
equalTo: '#password1'
}
},
messages: {
username: {
required: I18n.t('validation.register.username')
},
city_id: {
required: I18n.t('validation.register.city')
},
email: {
required: I18n.t('validation.register.email'),
email: I18n.t('validation.register.email_f')
},
terms_of_use: {
required: I18n.t('validation.register.tos')
},
password1: {
required: I18n.t('validation.register.password1'),
rangelength: I18n.t('validation.register.password_l')
},
password2: {
required: I18n.t('validation.register.password2'),
equalTo: I18n.t('validation.register.password_match')
}
}
});
爲什麼不改變價值形態'0'到' 「」'並設置所需的規則 –
請參閱http:// jsfiddle.net/arunpjohny/YzFZM/3/ –
不知道什麼是錯的,但一定要關閉你的選擇標籤 – megawac