Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Filtering CGI Input

by crashtest (Curate)
on Apr 24, 2005 at 06:15 UTC ( #450882=note: print w/replies, xml ) Need Help??


in reply to Filtering CGI Input

My input should be any number from 0 to 99999.
Well, then why use regular expressions at all? Isn't this just a simple number comparison? How about:
if ($sid < 0 or $sid > 99_999){ ... }

Replies are listed 'Best First'.
Re^2: Filtering CGI Input
by davidj (Priest) on Apr 24, 2005 at 07:10 UTC
    No, it is not that simple as the following code demonstrates:
    #!/usr/bin/perl use strict; my $num = "123abc"; print "valid\n" if $num > 0 && $num < 99999; exit;
    This will print 'valid', even though it does not meet the OP's criteria.

    Thus, if the value "123abc" is passed from a web form to a cgi script, the code you suggest will validate it. The reason for this is because when using numeric comparisons, Perl will treat any string that begins with a number as a number. This is clearly not what the OP wants.

    davidj

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://450882]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2019-05-25 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (152 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!