"Casey West" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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 >
This is true if there is a 5 digit number somewhere in the string, so you will get true even if length( $_ ) > 5. Use: /^\d{5}$/ to get true if the string is a 5 digit number. Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]