- or download this
# true if $string consists solely of allowed chars (and isn't empty)
$string =~ m/^[\s\d-\(\)\.]+$/;
# or, we could be true if $string contains anything except allowed cha
+rs
$string =~ m/[^\s\d-\(\)\.]/;
- or download this
$string =~ m/^[\s\d-\(\)\.x]+|(?:[Ee]xt[\.]*)*$/;
- or download this
sub is_valid {
# check to see if an entry consists of valid "phone number" chars.
...
# Ext or ext or x and digits.
return ( $phone =~ m/^\d+(?:(?:[Ee]xt)|x)*\d$/ );
}
- or download this
unless ( is_valid($FORM{'phone'} ) {
send_error("$FORM{'phone'} doesn't meet validity test");
exit;
}
- or download this
$phone =~ m{^\d+[\d\-\.\s\(\)]+(?:(?:[Ee]xt[\.]*)|x)*\d$};
- or download this
# valid number
unless ($FORM{'phone'} =~ /^\d+[\s\d-\(\)\.]+$/) {
...
# don't die if zero-length!
die "Bad ext" if length($FORM{'ext'});
}