in reply to integer validation

$foo = $query->param('should_be_int'); warn "Not an integer!" if ($foo =~ /[^0-9\-]/)
Replace the warn with whatever error handling suits your taste.
EDIT:Sigh. Totally forgot negative integers. =( Fixed.

Trinary

Replies are listed 'Best First'.
Re: Re: integer validation
by isotope (Deacon) on Apr 28, 2001 at 02:03 UTC
      I try to specify exactly what is valid:

      Then wouldn't you want /\A-?\d+\z/?

      If it's there, $ will match a single newline at the end of your string, and you'd end up matching something bogus like "7\n".

          --k.


      Jeez. Of course you're right.

      Something about quarter past 4 on a warm friday afternoon seems to have made thinking difficult.

      Trinary