in reply to Re: Filtering CGI Input
in thread Filtering CGI Input

I want to modify this filter so that it will accept lat/longs (-88.88888) that is 9 characters long and can include 0-9 and - and .

So does this look right?

~/^\d|\c(.|-)$/

All that I really want to do is make sure no other characters get in there except digits (0 thru 9) and the "." and "-" characters.

Replies are listed 'Best First'.
Re^3: Filtering CGI Input
by Tanktalus (Canon) on Apr 26, 2005 at 04:10 UTC

    9 characters long? Does 1.3456789 count? Or do you really mean 5 digits after the decimal place only? I'm assuming the latter. And that the - sign doesn't count.

    /^-?(\d{1,3}(?:\.\d{1,5})?)$/
    That is, an optional leading - sign, followed by 1 to 3 digits (to allow for 180 degrees East/West), followed, optionally, by a dot, and then 1 to 5 more digits.

    Better yet, try:

    use Regexp::Common; /^$RE{num}{decimal}{-places=>'0,5'}$/ and $_ <= 180;
    No sense reinventing the wheel. :-)