#!/usr/bin/perl use strict; use warnings; use IO::Prompt::Hooked; my $days = prompt( message => "Enter no of days older (1-90):", error => "Invalid input, please try again\n", validate => sub { my $days = shift; return ( $days =~ /^[1-9]\d?$/ and $days <= 90 ); }, ); print "You entered $days days\n\n";
The following sample run shows the recovery from several errors.
:tt.pl Enter no of days older (1-90): a Invalid input, please try again Enter no of days older (1-90): ! Invalid input, please try again Enter no of days older (1-90): 333 Invalid input, please try again Enter no of days older (1-90): 99 Invalid input, please try again Enter no of days older (1-90): 07 Invalid input, please try again Enter no of days older (1-90): 9 You entered 9 days :
In reply to Re: Validation of UserInput is a positive Integer or not?
by BillKSmith
in thread Validation of UserInput is a positive Integer or not?
by G Nagasri Varma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |