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?
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 .
Use the Contains() method to check if a string contains a word or not.
Use
/^(?!some|words|in|blacklist)[a-zA-Z]+$/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With