开发者

jquery validator addMethod question

Working with JQuery Validator and just have a quick question. I'm using addMethod to define a custom validation for Australian phone numbers based on a regex. 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.开发者_开发百科

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.

Is there any way to add a reusable function into the call for 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.

The way you did called the regexPhone function before appending in the callback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜