I have a jQuery validation regex that checks if phrase(s) are included:
$.validator.addMethod("regex", function(value, element, regexp) {
return this.optional(element) || regexp.test(value);
}, "You must include the required keyword phrase(s).");
If I have multiple phrases to check, i'm adding them with:
$("#text").rules("add", { regex: /phrase one/i });
$("#text").rules("add", { regex: /another phrase/i });
$("#text").rules("add", { regex: /test phrase/i });
The problem i'm having is that it only checks for the last phrase rule, meaning if "test phrase" is included, but the others aren't, it will accept it. I need it to check to make sure all phrases are included.
I would also like the error message to be able to include the phase that's missing, example, if "another phrase" is missing, the error will be:
You must include the required phrase: another phrase
Thx