On Thursday 22 Apr 2010, Mimi Cafe wrote:

> I am trying to match words or complete phrase (excluding special characters)
> like:

> 1.    Tom 
> 2.    Tom and Jerry 
> 3.    Audio A4 Quattro 

> 
> I need to ensure users cannot feed my program with special characters so I
> tried this below, but it doesn't match correctly.

<Code>
if ($string =~ /^[\w\s]*$/) {print "$string\n";}
else {print  "Invalid Keyword. Please check and try again\n";}
</Code>

Audio A4 Quattro -> Audio A4 Quattro
Tom & Jerry -> Invalid Keyword. Please check and try again

Regards,
Akhthar Parvez K
http://Tips.SysAdminGUIDE.COM
UNIX is basically a simple operating system, but you have to be a genius to 
understand the simplicity - Dennie Richie

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to