rohit rohit - 2 months ago 9
HTML Question

Regex to allow only string but not combination of word “test”

^(?!test$)[a-zA-Z'.\s]{2,40}$


doesn't allow the word 'test' as an input, it also don't allow the numbers. How can i modify this regular expression as it will exclude all combinations of 'test'? means Test, test, TEst, tEst etc. etc. also i dont want to allow any special characters

Answer

You just need to add case-insensitive modifier.

/^(?!test$)[a-z'.\s]{2,40}$/mi

or

If you don't want the word test to present anywhere in the input string then you have to use the below regex.

/^(?!.*test.*$)[a-z'.\s]{2,40}$/mi