http://qs321.pair.com?node_id=614455


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.