Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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"; }
or
if ($DataEntry =~ /^[0-9]+$/) { print "good entry\n"; } else { print "bad entry\n"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-01-23 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?