
Kanji
User
Jun 15, 2000, 3:34 PM
Post #3 of 7
(513 views)
|
Uh ... no. That snippet of code would tell you if the variable contained a number because your regexp isn't anchored (ie, "A1 Steak Sauce" would be considered a number because it contains a 1). Instead, you'd want something like ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> if ( $field =~ /^\d+$/ ) { ... } else { ... }</pre><HR></BLOCKQUOTE> ... but that only works for whole numbers. If you want negative numbers, decimals, etc. you'd need to modify the regexp accordingly ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> /^(-?(\d+|\d+\.\d+)$/</pre><HR></BLOCKQUOTE> ... which considers 1, 0.1, and -22 all valid numbers.
|