我使用jQuery驗證插件1.9.0(來自http://bassistance.de/)。問題是,我不知道如何驗證文本字段只有當用戶輸入的東西。如果用戶沒有寫任何字段不應該按要求處理。使用jQuery驗證插件驗證表格
0
A
回答
2
不要設置required規則選項 -
rules : {
text1 : {
required: false, // Or do not specify the option
minlength: 3 // validation if it has value
}
},
+0
謝謝。有用 ! – user1014152
0
if (value != '') {
// Do your validation here
}
0
你可以通過一個函數來驗證規則。例如
$("#demoForm").validate({
rules: {
"requiredField": {sampleRule: function(e){
var input = $(e);
if(input.val())
return true;
return false;
}
}
},
messages : {
"requiredField": "This field is invalid"
}
其中「sampleRule」可以是任何你想要的規則,例如。 「需要」或「最小長度」。該功能賦予添加有條件規則的權力。
相關問題
- 1. 添加驗證方法「jQuery的驗證插件」使用jQuery驗證插件
- 2. 使用jQuery驗證插件
- 3. 使用jQuery驗證插件
- 4. 使用jQuery驗證插件
- 5. 使用JQuery驗證插件
- 6. 驗證表格使用jquery
- 7. JQuery驗證器插件驗證條件
- 8. 使用jQuery驗證插件驗證表單字段?
- 9. 使用jQuery驗證插件驗證表單子集
- 10. 使用jQuery驗證插件驗證順序日期列表
- 11. 如何使用jQuery驗證插件驗證表單?
- 12. 如何使用jQuery驗證插件驗證正則表達式?
- 13. jquery表單驗證插件
- 14. 使用jquery驗證表單(插件)
- 15. jquery驗證插件,選擇值驗證
- 16. 驗證多選與jQuery驗證插件
- 17. jQuery的驗證插件 - 沒有驗證
- 18. jQuery驗證插件複選框驗證
- 19. jQuery驗證插件:驗證複選框
- 20. jQuery驗證插件的逐步驗證
- 21. jQuery驗證和驗證插件
- 22. JQuery驗證插件 - 無法驗證類
- 23. jQuery插件/驗證
- 24. jquery - 驗證插件
- 25. jQuery驗證插件
- 26. JQuery驗證插件
- 27. JQuery驗證插件
- 28. jquery驗證插件
- 29. jQuery驗證插件
- 30. jQuery驗證插件
您是否設置了所需的選項? http://rocketsquared.com/wiki/Plugins/Validation/Methods/required – mamoo
@mamoo,是的,但我只想驗證,如果文本字段包含一些文本 – user1014152