Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Check for Positive Integer entry only

by friedo (Prior)
on May 09, 2007 at 17:16 UTC ( #614455=note: print w/replies, xml ) Need Help??


in reply to Check for Positive Integer entry only

This should do it:
if ( $DataEntry =~ /^\d+$/ ) { print "good entry"; } else { print "bad entry"; }

Replies are listed 'Best First'.
Re^2: Check for Positive Integer entry only
by Nkuvu (Priest) on May 09, 2007 at 17:54 UTC

    Add in a test for zero -- that passes through this regex, but is not a positive integer by any definition I'm aware of.

Re^2: Check for Positive Integer entry only
by ikegami (Patriarch) on May 12, 2007 at 16:17 UTC
    That also passes for "123\n" which could be good or bad. Use \z instead of $ if you don't want to allow a trailing \n.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2023-09-22 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?