CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
limiting input



Apr 16, 2001, 2:00 AM

Post #1 of 4 (339 views)
limiting input Can't Post

How can I limit the characters in a text input box on my form to just text and numbers. I don't want any other characters or returns. Is there a way??



Apr 16, 2001, 3:03 AM

Post #2 of 4 (337 views)
Re: limiting input [In reply to] Can't Post

If you want to check what they typed in for non alpa numeric characters you could use this,

use CGI qw/:standard/;

if ($input !~ /[A-Za-z0-9]/){
print "There are characters that aren't numbers or letters in here";

To get rid of returns,


That's newlines & returns, from a windows pc they will be wrapped together.

Hope that helped,



Apr 16, 2001, 8:33 AM

Post #3 of 4 (331 views)
Re: limiting input [In reply to] Can't Post

Your two regexes have bugs in them.

The first returns true only if the string doesn't have a single letter or number in it. To make sure a string ONLY has letters and numbers, you should do if ($str =~ /[^A-Za-z0-9]/) { bad data ... }.

The other regex uses | in a character class incorrectly. Character classes are for characters -- they are automatically using alternation. Putting the | character in a character class makes it a valid character to be matched. And removing characters is done more efficiently with tr///, like so: $str =~ tr/\n\r//d. That removes all newlines and carriage returns.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


Apr 16, 2001, 3:27 PM

Post #4 of 4 (320 views)
Re: limiting input [In reply to] Can't Post

 Sorry about that there jerky, I see I wrote that out wrong myself, I had a terribly long day yesterday,

Since I don't have much of a rep for intelligence anymore and my advice probably will be taken with a grain of salt I think I won't be coming here anymore either.



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives