Instead of using the
/regex/g
syntax, you can construct a new RegExp object:var re = new RegExp("regex","g");
You can dynamically create regex objects this way. Then you will do:
"mystring".replace(re, "newstring");
jQuery.validator.addMethod( "regex", function(value, element, regexp) { var re = new RegExp(regexp,"g"); return this.optional(element) || re.test(value); }, "Please check your input." );will return true or false
评论
发表评论