I'm looking for criticism of my regular expression that looks for a number to be >= 0 and < 1 (i.e. 0, 0.00001, and .99999 are OK but 1, -0.00001, and -1 are NOT OK). I'm using the RE to untaint a number from a CGI form. The regex seems to work and is based on a regex in PerlFaq4 that matches decimal numbers. Here is the code in my CGI script that handles the untainting.
my ($num) = $_num =~ /^(0(\.\d+)?|\.\d+)$/;
Please comment on the accuracy and if there is a better way to do it.
Thank you,
lupey
<bold>Update</bold> Thank you everybody for your suggestions. I seem to like tlm's answer the best. I didn't realize that I could separate tainting from checking the numerical properties of a scalar.
In reply to Match number >= 0 and <1 by lupey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |