in reply to Re: Validation of UserInput is a positive Integer or not?
in thread Validation of UserInput is a positive Integer or not?
I'd suggest a couple minor changes to update this line in your original version:
with this one:if ( (0 < $days) && ($days <= 90) && ($days =~ /^\d\d$/) )
if ( ($days =~ /^\d+$/) && (0 < $days) && ($days <= 90) )
This avoids printing a warning of Argument "x" isn't numeric in numeric lt (<) by doing the regex test first (consider what the code does with an alpha-string.) Further, the original regex disallows values like "1" which are within the desired spec. No real harm in allowing any number of digits since the later tests verify the range, although using a repeat of {1,2} could also work (I personally try to avoid it as it makes updating the range in the future more complex.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Validation of UserInput is a positive Integer or not?
by ww (Archbishop) on Dec 08, 2015 at 13:45 UTC | |
by Apero (Scribe) on Dec 08, 2015 at 14:01 UTC | |
by ww (Archbishop) on Dec 08, 2015 at 14:06 UTC |