Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string is alphabetic and does not contain some specific words

I use /^[a-zA-Z]+$/ to check if a string is alphabetic and /^((?!some|words|in|blacklist).)*$/ to validate if it does not contain some specific words.

How can I check for both conditions in a single regex pattern?

like image 949
Lewis Avatar asked Apr 28 '15 07:04

Lewis


People also ask

How do I check if a string not contains a specific word?

You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .

How do I check if a string contains a specific word?

Use the Contains() method to check if a string contains a word or not.


1 Answers

Use

/^(?!some|words|in|blacklist)[a-zA-Z]+$/
like image 78
Denys Séguret Avatar answered Oct 22 '22 05:10

Denys Séguret