[英]jquery validator addMethod question
Working with JQuery Validator and just have a quick question. 使用JQuery Validator并仅需一个简单的问题。 I'm using addMethod to define a custom validation for Australian phone numbers based on a regex.
我正在使用addMethod基于正则表达式为澳大利亚电话号码定义自定义验证。 This is a method that I'd like to use in multiple pages, so I want to define the function in an external .js file, and pop it into the addMethod call.
我想在多个页面中使用此方法,因此我想在一个外部.js文件中定义该函数,然后将其弹出到addMethod调用中。
If I use: 如果我使用:
$.validator.addMethod('phone', regexPhone(value), 'Please enter a valid phone number');
I get a reference error: can't find value, but if you build the function straight into the addMethod call, you use the parameter value. 我收到一个参考错误:找不到值,但是如果直接将函数构建到addMethod调用中,则使用参数值。
Is there any way to add a reusable function into the call for addMethod? 有什么方法可以将可重用函数添加到addMethod的调用中?
Ta, Ryan. 塔,瑞安。
Try 尝试
$.validator.addMethod('phone', regexPhone, 'Please enter a valid phone number');
The second parameter in addMethod is a callback, This will call the function regexPhone. addMethod中的第二个参数是一个回调,它将调用函数regexPhone。
The way you did called the regexPhone function before appending in the callback. 在追加回调之前,您调用regexPhone函数的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.