$pattern = '/^(^[\`\~\@\#\$\%\^\&\\])+$/';
if(preg_match($pattern, $textToSearch)){
exit('Bad text.');
}
The code above is supposed to exit upon the first occurrence of any element in the pattern above. But it is not working. Will anyone please help me arrive at a working code sample?
Since any occurrence of any of the listed special characters should mark the input as bad, you can make use of the regex: [\`\~\@\#\$\%\^\&\\\\]
:
$pattern = '/[\`\~\@\#\$\%\^\&\\\\]/';
if(preg_match($pattern, $textToSearch)){
exit('Bad text.');
}