jQuery验证规则 [英] jquery validation rules
本文介绍了jQuery验证规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 我的电话验证取决于一个复选框(不,请勿通过电话与我联系).如果选中此选项,则不需要运行电话验证.我四处搜寻,发现依赖" 功能.
- My phone validation depends on a checkbox (no, don't contact me via phone). If this is checked, then I will not need run the phone validation. I googled around and found 'depends' function.
我有
$("#myForm").validate({
....
rules: {
phone1: {
required: {
depends: "!#pri_noPhone:checked"
},
number: true,
minlength:3,
}
它不会引发错误,但仍会尝试验证电话号码.
It doesn't throw an error, but it still tries to validate the phone number.
- 在规则下:如何确保电子邮件和ConfirmEmail相同?我有规则,并且消息分开.
推荐答案
尝试如下操作:
"#phone1": {
number: true,
minlength:3,
required: function(element){
return ($('#pri_noPhone_wrapper input:checked').val() == 'True');
}
}
HTML(看了之后我忘了添加包装HTML)
The HTML (after looking at this I forgot to add the wrapper HTML)
<span id='pri_noPhone_wrapper'>
Phone:
<input type="checkbox" name="pri_noPhone" value="what ever" />
</span>
这篇关于jQuery验证规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文