Answer the question
In order to leave comments, you need to log in
How to write regular expression validation for characters that should not be present?
Hello, already the brain refuses from fatigue, but it is necessary to add the validation of the fields. How to correctly check the field for the presence of prohibited characters in any part of the word? No matter what I tried, it doesn't work...
Answer the question
In order to leave comments, you need to log in
Why is this regular? Use the native PHP function strpbrk()
As an example:
$illegal = "#$%^&*()+=-[]';,./{}|:<>?~";
$my_string = "Hello & World";
echo (false === strpbrk($my_string, $illegal)) ? 'Allowed' : "Disallowed";
return preg_match('/[#$%^&*()+=\-\[\]\';,.\/{}|":<>?~\\\\]/', $string);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question