# 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 chars $string =~ m/[^\s\d-\(\)\.]/; #### $string =~ m/^[\s\d-\(\)\.x]+|(?:[Ee]xt[\.]*)*$/; #### sub is_valid { # check to see if an entry consists of valid "phone number" chars. my ($phone) = @_; $phone =~ s/[\-\.\s\(\)]+//g; #remove punct. and spaces # return 1 if begins with digits and is followed by # Ext or ext or x and digits. return ( $phone =~ m/^\d+(?:(?:[Ee]xt)|x)*\d$/ ); } #### unless ( is_valid($FORM{'phone'} ) { send_error("$FORM{'phone'} doesn't meet validity test"); exit; } #### $phone =~ m{^\d+[\d\-\.\s\(\)]+(?:(?:[Ee]xt[\.]*)|x)*\d$}; #### # valid number unless ($FORM{'phone'} =~ /^\d+[\s\d-\(\)\.]+$/) { die "Bad phone"; } #valid ext, if it exists unless ($FORM{'ext'} =~ /^\d+$/) { # don't die if zero-length! die "Bad ext" if length($FORM{'ext'}); }