尝试添加新的 jquery 验证器方法
我正在尝试添加一个验证器规则,其工作方式如下:
当我们在一个元素上应用这个规则时,它应该只被验证 关于我们通过 params 传递的元素的非空值。 意味着,当且仅当通过的其中之一时,它必须验证自身 元素具有非空值。
我正在尝试的规则:
jQuery.validator.addMethod("reqAfter",function(a,b,c){
for(var i in c){
var $d=$(c[i]);
return !($d.length&&$d.val()!==""&&a=="");
}
},"Please provide some value!");
例如:
rules: {
sField: { reqAfter: ['#startD', '#endD'] },
startD: { regex: /^(\d{4,4})-(\d{2,2})-(\d{2,2})$/, reqAfter: ['#sField'] },
endD: { regex: /^(\d{4,4})-(\d{2,2})-(\d{2,2})$/, reqAfter: ['#sField', '#startD'] }
}
对于这种形式:
I am trying to add a validator rule which will work like:
When we apply this rule on an element then it should only be validated
on the non-empty values of the elements which we passed through params.
Means, it must validate itself if and only if one of the passed
elements have non-empty value.
the rule what I am trying:
jQuery.validator.addMethod("reqAfter",function(a,b,c){
for(var i in c){
var $d=$(c[i]);
return !($d.length&&$d.val()!==""&&a=="");
}
},"Please provide some value!");
like:
rules: {
sField: { reqAfter: ['#startD', '#endD'] },
startD: { regex: /^(\d{4,4})-(\d{2,2})-(\d{2,2})$/, reqAfter: ['#sField'] },
endD: { regex: /^(\d{4,4})-(\d{2,2})-(\d{2,2})$/, reqAfter: ['#sField', '#startD'] }
}
for this form:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己整理一下。
工作验证器方法是:
谢谢我......
I sort it by myself.
Working validator method is:
Thanks to me...