Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Check for Positive Integer entry only

by mreece (Friar)
on May 09, 2007 at 21:59 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://614505]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found