I am trying to test user input to ensure it contains special character or
symbols that could cause problems to my program or database.
The user will enter a keyword in the web form to search in my database, and
I want to ensure I don't play around with special character otherwise any
word or phrase is valid.
I have changed my regex several times, but still doesn't work and now I have
something bizarre and it doesn't work either.
$string !~ /^[A-Za-z0-9]+/ # did not work when 2 words are supplied.
$string !~ /(^[A-Za-z0-9])+\s*$1/ # did not work.
if ($string =~ /!|\$|%|\?|\^|\+|@|'|\\||/){ # doesn't work.
print qq(<p style="font-weight: bold;">Invalid Keyword</p>);
print qq(<p>You have entered an invalid search keyword.
<br /> Please go back and enter a valid word.</p>);
footer();
exit;
}
Any idea how to match this properly?
Mimi
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/