On Wed, 26 Feb 2003 16:30:56 -0800, [EMAIL PROTECTED] (T. Murlidharan Nair) wrote:
>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. $_ = 4.01; if (/\D/) { print "has nondigits\n" } if (/^\d+$/) { print "is a whole number\n" } if (/^-?\d+$/) { print "is an integer\n" } if (/^[+-]?\d+$/) { print "is a +/- integer\n" } if (/^-?\d+\.?\d*$/) { print "is a real number\n" } if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print "is a decimal number\n" } if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print "a C float\n" } ° Also check out the Regex::Common module, it has number-type detection. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]