I've got the following addMethod for jquery validation:
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Invalid number of characters entered."
);
And in my field I want to validate that the user enters 7, 9, 12, 13, or 15 chars, I can't get the regex to work. I've tried each of the following with their corresposing results:
"......."
- Validates that 7 chars are entered
".......| ........."
- Validates that 7 chars are entered but claims error when 9 are entered.
'/^([a-z0-9]{7,}|[a-z0-9]{9,})$/'
- Fails to validate anything.
I realize there are plenty of resources out there but this is my first use of regex and I can't seem to put the right combination together. Please help if you see a solution. Thanks.