我實現它在遊戲框架,對我來說像這樣工作:
1)請注意,我用數據規則equalTo輸入標籤的id inputPassword1。用戶窗體在我的模態 的代碼段:因爲我內的模態
$(document).on("click", ".createUserModal", function() {
$(this).find('#userform').validate({
rules: {
firstName: "required",
lastName: "required",
nationalId: {
required: true,
digits:true
},
email: {
required: true,
email: true
},
optradio: "required",
password :{
required: true,
minlength: 5
},
password2: {
required: true
}
},
highlight: function (element) {
$(element).parent().addClass('error')
},
unhighlight: function (element) {
$(element).parent().removeClass('error')
},
onsubmit: true
});
});
用於驗證
<div class="form-group">
<label for="pass1">@Messages("authentication.password")</label>
<input class="form-control required" id="inputPassword1" placeholder="@Messages("authentication.password")" type="password" name="password" maxlength=10 minlength=5>
</div>
<div class="form-group">
<label for="pass2">@Messages("authentication.password2")</label>
<input class="form-control required" data-rule-equalTo="#inputPassword1" id="inputPassword2" placeholder="@Messages("authentication.password")" type="password" name="password2">
</div>
2)希望它可以幫助別人:)。
爲什麼不關閉:required:false? –
是的,我試過了,但確認無效了。 我的意思是password_confirm字段是必需的如果密碼字段不爲空 – ldrocks
哦,那我想你可能需要一個自定義的驗證器:http://docs.jquery.com/Plugins/Validation/Validator/addMethod –