Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Check for Positive Integer entry only

by mreece (Friar)
on May 09, 2007 at 21:59 UTC ( #614505=note: print w/replies, xml ) Need Help??

in reply to Check for Positive Integer entry only

i'm not a big fan of \d, since it can lead to unexpected results: matching things that are "digits" but not useable as perl or database integers. when unicode enters the picture, there are 268 or so unicode characters that \d matches against.

what you probably want here is a string that starts with a number 1-9, followed by more numbers 0-9 (assuming that 03 is a bad entry), or just one or more numbers 0-9 (if 03 is a good entry).

if ($DataEntry =~ /^[1-9][0-9]*$/) { print "good entry\n"; } else { print "bad entry\n"; }
if ($DataEntry =~ /^[0-9]+$/) { print "good entry\n"; } else { print "bad entry\n"; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2023-03-28 05:41 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (66 votes). Check out past polls.