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.
精彩评论