我必須根據使用條件最小長度。(我想在自己的它也不能工作,反正)jQuery驗證插件的使用MINLENGTH不起作用
沒有與「需要」的規則沒有問題。如果條件成立,我可以看到所需的消息,「所需」規則按預期工作,我也可以在控制檯上看到「快樂的一天」。
但即使我可以在控制檯中看到「最小長度5」,它的行爲就像表單一樣。
我在哪裏錯了?謝謝。
if($('form#form_validation_reg_generate_user').valid({
rules: {
'userPassword':{
required:(function() {
if($('#userPassword').val().length >0) {
console.log('happy day');
return true;
}
else{
console.log('happy day false');
return false;
}
})(),
minlength:(function() {
if($('#userPassword').val().length >0) {
console.log('min length 5');
return 5;
}
else{
console.log('min length 0');
return 0;
}
})()
}
}
}))
'規則:{ userPassword:{ required:true, minlength:5 } },'用這些代碼警告,如果'userPassword'中沒有字符。我明白沒有機會有條件地驗證輸入,對嗎?由於 – merveotesi 2013-03-10 17:37:43
另外這款'$( '#形式form_validation_reg_generate_user')驗證({ 規則:{ 的userPassword:{ 使用MINLENGTH:5 } }'是沒有意義的,而不需要 – merveotesi 2013-03-10 17:39:15
@tuxi,「'minlength'沒有。所需要的「是非常有意義的......它只是意味着該字段是可選的,但是,如果你填寫它,它必須至少有5個字符。是的,你可以有條件規則,但你需要準確解釋你想要什麼,而不是通過查看破碎的代碼來進行猜測 – Sparky 2013-03-10 17:42:39