: hi
: i want to get a errror message if i enter a string value instead
: of integer in a text field
: can anybody plz help me
:
Here's a couple different approaches:
sub check_area_code {
my $file = "/path/error.log"
my $LOGOUT = FileHandle->new(">> ${file}") or die ("Can not write to ${file}: $!");
my $len = do { length $area_code };
if ( $len == 3 && ( $area_code =~ /[0-9][0-9][0-9]/ ) && (! ($area_code =~ /911/ )) ) {
# do something...
} else {
print $LOGOUT "error invalid area code in phone number!\n";
}
$LOGOUT->close();
}
OR Have you tried setting up a condition like such and send in one char at a time:
if (! ($passed_var =~ /\d/) ) {
print "passed_var is not a number!\n";
# you could either print this to an error log file or to STDERR.
# not sure what you wanted from here on. ?
# or maybe set a variable to 0 and use it like a flag of some sorts.
} else {
print "All is ok, we have a number.\n";
}
Hope that helps.

Regards,
JoeMc