I'm trying to validate a input field with jquery and the validate plugin. But my regex keeps failing. The regex works perfectly if I use ajax and run it through a php file. But I dont want to run a ajax request for every character thats written in the input field. Do regex behave diffrently in javascript? Do I have to place the flag another place?
Uncaught SyntaxError: Invalid regular expression: /^\p{L}[\p{L} \'&-]*[\p{L}]$/: Invalid escape
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
);
contact_name: {
required: true,
regex: /^\p{L}[\p{L} \'&-]*[\p{L}]$/u
}