jQuery rules add mask
Good day,
I am support an project that develop by other team.
I saw some jQuery code that I am not really understand what the code is doing, I plan to amend on it but at first I need to know what it want to do first.
Here is the code:
$(function(){
$(':input[name=country]').rules('add', {
required: true,
mask: /^[a-zA-Z0-9 ]+$/
});
});
I am suspecting it is mask method, for example which is:
$(':input[name=country]').mask("0000-0000"); // this is work
But I try to run it but it fail, hitting error:
Cannot read property 'call' of jquery.validate.min.js:16 undefined
Answers 1
The
.rules()
method is part of the jQuery Validate plugin and has absolutely nothing to do with the.mask()
method which is part of another plugin. This code is trying to dynamically add form validation rules to aninput
element withname="country"
.The error is because jQuery Validate is looking for a rule called
mask
where there is no "mask" rule in this plugin.Your only options are:
mask
using the.addMethod()
method