Reputation: 11
$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?
Upvotes: 1
Views: 495
Reputation: 455470
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.');
}
Upvotes: 1