in reply to Filtering CGI Input
Your regexp is matching anything that has the literal string "0-9" in it. And then the !~ negates that match. Thus, since anything you've tried probably does not include the literal string "0-9" somewhere in it, the full expression is always true.
You want to match a character class - e.g., \d matches all digits, thus using /\d/ is a bit closer. What this does is match any digit, anywhere in the string.
You actually want to match 1 to 5 digits. So you can use the {} modifier: /\d{1,5}/. This matches anywhere from 1 to 5 digits, anywhere in the string. But that still matches "a1b" since it has somewhere between 1 and 5 digits. So you want to anchor the match to both the beginning and the end. And thus we get /^\d{1,5}$/.
Hope that helps. perlretut may help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Filtering CGI Input
by awohld (Hermit) on Apr 26, 2005 at 03:45 UTC | |
by Tanktalus (Canon) on Apr 26, 2005 at 04:10 UTC |