I'm trying to add validation to a form field so that if it contains a certain word, an error is displayed. At the moment I have this:
Validation.Add("field-1", Validator.Regex("^((?!TEST)(?!test).)*$", "Field may not contain 'test'"));
This works fine for "TEST" and "test", but won't prevent someone entering "tESt".
I've tried adding the case insensitive flag, but this made the regex stop working completely:
Validation.Add("field-1", Validator.Regex("/^((?!TEST)(?!test).)*$/i", "Field may not contain 'test'"));
I also read here that (?i) can be used to ignore case, but that didn't work either - maybe I'm putting it in the wrong place:
Validation.Add("field-1", Validator.Regex("^((?i)(?!TEST)(?!test).)*$", "Field may not contain 'test'"));
Is this doable without adding every possible variation of "test"?
"(?i)^(?!.*TEST).*$". It also seems your"^((?i)(?!TEST)(?!test).)*$"should also work (although a tempered greedy token here is an "overkill").(?i)won't work in JS, it will only work in .NET (well, and in some other regex flavors).(?i). You have to use^(?!.*[Tt][Ee][sS][tT]).*$