On Sun, 18 Apr 2010 17:09:59 +0100 Mimi Cafe <mimic...@googlemail.com> wrote:
> 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. You might want to simply remove theses characters, $string =~ s/[`\\"|!$\^&\...@#?><\s]//g <---an example only > > Any idea how to match this properly? Try one of the posix character classes.[[:class]] where class would probably be alnum (See http://perldoc.perl.org/perlre.html ) If the data base contains names like O'Rourke, then you might have to rethink your database or add the ' to the list of allowed characters Owen -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/