May 1, 2009 #1 dreamstreet Programmer Joined Jan 24, 2003 Messages 25 Location US $username = param('username'); Hello, How do i make sure that the user has entered only letters/numbers and not any illegal charters like @_)(). thanks -a d
$username = param('username'); Hello, How do i make sure that the user has entered only letters/numbers and not any illegal charters like @_)(). thanks -a d
May 1, 2009 2 #2 KevinADC Technical User Joined Jan 21, 2005 Messages 5,070 Location US Next time please psot what you have tried to solve your programming requirements, even if it did not work. Only alpha and digits: Code: unless ($username =~ /^[a-zA-Z0-9]+$/) { print "You're a naughty boy!\n"; } Only alpha, digits and underscore (same as \w): Code: if ($username =~ /\W/) { print "You're a naughty boy!\n"; } \W is the compliment of \w, so anything that is not a-zA-Z0-9_ will return true and indicate illegal characters are present. ------------------------------------------ - Kevin, perl coder unexceptional! Upvote 0 Downvote
Next time please psot what you have tried to solve your programming requirements, even if it did not work. Only alpha and digits: Code: unless ($username =~ /^[a-zA-Z0-9]+$/) { print "You're a naughty boy!\n"; } Only alpha, digits and underscore (same as \w): Code: if ($username =~ /\W/) { print "You're a naughty boy!\n"; } \W is the compliment of \w, so anything that is not a-zA-Z0-9_ will return true and indicate illegal characters are present. ------------------------------------------ - Kevin, perl coder unexceptional!
May 1, 2009 Thread starter #3 dreamstreet Programmer Joined Jan 24, 2003 Messages 25 Location US thank you d Upvote 0 Downvote
May 1, 2009 Thread starter #4 dreamstreet Programmer Joined Jan 24, 2003 Messages 25 Location US Hello Kevin, It does work but it seems to let the "()" go in. How can I block the something "(ss))))". if ($uname =~/^[a-zA-Z0-9]+$/)) { $error="User name can only contain letters or numbers."; } thank you d Upvote 0 Downvote
Hello Kevin, It does work but it seems to let the "()" go in. How can I block the something "(ss))))". if ($uname =~/^[a-zA-Z0-9]+$/)) { $error="User name can only contain letters or numbers."; } thank you d
May 1, 2009 #5 KevinADC Technical User Joined Jan 21, 2005 Messages 5,070 Location US You did not pay close attention to the code I posted. Ignoring the syntax error in your code it would be like this: Code: $uname = '(ss))))'; [red]unless[/red] ($uname =~ /^[a-zA-Z0-9]+$/) { print "User name can only contain letters or numbers."; } or: Code: $uname = '(ss))))'; [red]if[/red] ($uname =~ /\W/) { print "User name can only contain letters or numbers and the underscore."; } ------------------------------------------ - Kevin, perl coder unexceptional! Upvote 0 Downvote
You did not pay close attention to the code I posted. Ignoring the syntax error in your code it would be like this: Code: $uname = '(ss))))'; [red]unless[/red] ($uname =~ /^[a-zA-Z0-9]+$/) { print "User name can only contain letters or numbers."; } or: Code: $uname = '(ss))))'; [red]if[/red] ($uname =~ /\W/) { print "User name can only contain letters or numbers and the underscore."; } ------------------------------------------ - Kevin, perl coder unexceptional!
May 1, 2009 Thread starter #6 dreamstreet Programmer Joined Jan 24, 2003 Messages 25 Location US ah ok. gotcha..thanks a lot d Upvote 0 Downvote