> -----Original Message----- > From: Al Hospers [mailto:[EMAIL PROTECTED]] > Sent: Friday, February 01, 2002 8:14 PM > To: [EMAIL PROTECTED] > Subject: validation > > > I need a regular expression that will only allow a variable to contain > digits. it should fail if there is anything else in the variable: > dollar signs, commas, dots, alphas, spaces, quotes etc. I thought the > following would work, I am obviously incorrect. > > return 1 unless ($Bid_Amount =~ [/d/] ); > > any help would be appreciated.
Assuming "return 1" means "bad", if the string must consist solely of digits, and an empty string is not allowed, you need: return 1 unless $Bid_Amount =~ /^\d+$/; # must be 1 or more digits The ^ and $ anchors are needed to match over the entire string. If an empty string is legal, the following will work, and are equivalent to one another: return 1 unless $Bid_Amount =~ /^\d*$/; # must be 0 or more digits return 1 if $Bid_Amount =~ /\D/; # disallow non-digit -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]