It was Wednesday, February 26, 2003 when Robert Wideman took the soap box, saying:
: >> I have a cgi that need to accept only numeric values. ie +ve or -ve
: >> real numbers.
: >> Is there a quick and easy way to check this. I was trying using a reg exp
: >> if(/^[-0-9][\.0-9]*/) {
: >> do something
: >> }
: >>
: >> but this breaks when the number is say --75.4 It still accepts if it
: >> has two - signs.
:
: I just created a script for testing on the CLI for requiring 5 digit zip
: code, for which i have imported 50,000 zip codes into a table for testing
: this.
:
: sub notenough{$zipentered}{
: while($zipentered !~ m/[0-9][0-9][0-9][0-9][0-9]/){
You're doing way too much work yourself! Let Perl do it. 'perldoc
perlre' will teach you about the '\d' sequence, meaning, match a
digit. Also, you should learn about the '{N}' construct, where 'N' is
the number of things before it that you want to macth. So, your regex
is as simple as this.
/\d{5}/ # match exactly five digits
: print "I require 5 numbers, no more, no less. Try Again.\n";
: print "Enter a zip code to search for: ";
: $zipentered=<>;
: }
: }
:
: The only problem that i have is that if i put in >5 it breaks but works if i
: put in <5.
: Hope this helps.
: Any fix for my problems are welcome, and needed.
Enjoy!
Casey West
--
The last good thing written in C++ was the Pachelbel Canon.
-- Jerry Olson
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]