Pass an object for regex
to separate the regex proper from the flags:
webAddr: {
regex: {regex: '^(http(s)?:\/\/)?(([a-z]+[a-z0-9-\\.]*)\\.)+[a-z]{2,}$',
flags:'i'},
maxlength: 256,
minlength: 4
},
(I've changed the flag from '\\i'
to 'i'
because I've never heard of '\\i'
as a flag.)
And modify your validation code like this:
$.validator.addMethod(
"regex",
function(value, element, param) {
var re = new XRegExp(param.regex, param.flags);
return this.optional(element) || re.test(value);
},
"Please check your input."
);
I've not tested this code so watch out for typos.