##############
sub check_email {
#print "Address keys=", @_, "
\n";
foreach $address (@_){
$address=$Form_Data->{"\$$address"};
next unless $address;
# print "Checking address.= $address
\n";
local ($name,$domain)=split/[\@|\%|\!]/,$address;
if ($name!~/^[\w\d<"][\w\d\,\.\%\-"<>\s]*$/){
push @errorlog,$address,"check_email";
push @errorlog,"First part of email address invalid";
next;
}
### break domain on '.' and check it for sanity
if ($domain eq ""){
push @errorlog,$address,"check_email";
push @errorlog,"No domain specified:$address";
last;
}
local(@d_regions)=split(/\./,$domain);
local ($region)=pop(@d_regions); # first check the last region
if ($region=~/^([a-zA-Z]{2,3})$/ || $region=~/^([0-9]{1,3}\]?)$/) {
next;
}else{
push @errorlog,$address,"check_email";
push @errorlog,"Domain part of email address:$domain invalid";
next;
}
$region=shift(@d_regions); #now check first region
if ($region=~/^(\[?[0-9]+)/ || $region=~/^([a-zA-Z0-9\-\#]+)$/) {
next;
}else{
push @errorlog,$address,"check_email";
push @errorlog,"Domain part of email address:$domain invalid";
next;
}
# now check everything else
foreach $region (@d_regions) {
if ($region!~/^([a-zA-Z0-9\-\#]+)$/) {
next;
}else{
push @errorlog,$address,"check_email";
push @errorlog,"Domain part of email address:$domain invalid";
next;
}
}
}
}
##############
sub check_phone {
foreach $phone (@_){
$phone=$Form_Data->{"\$$phone"};
unless ($phone){
next;
}
if ($phone !~/^\s*[\(\[]{0,1}\d{3}[\)\]]{0,1}[\.\-\ ]*\d{3}[\.\-\ ]*\d{4}(([\.\-\ ]*([xX]|ext\.{0,1}|Ext\.{0,1}))\s*\d{2,6}){0,1}\s*$/) {
push(@errorlog,$phone,"check_phone","invalid US phone number");
}
}
}
##############
sub check_zip {
foreach $zip (@_){
$zip=$Form_Data->{"\$$zip"};
unless ($zip){
next;
}
unless ($zip=~/^\d{5}$/ || $zip=~/^\d{5}\s*\-{0,1}\s*\d{0,4}$/){
push(@errorlog,$zip,"check_zip","invalid ZIP code entry");
}
}
}
##############
sub check_selectlist {
local($listname,$element);
while (@_){
$listname=shift(@_);
$element=shift(@_);
if ($Form_Data->{"\$$listname"} eq $element){
push(@errorlog,$listname,"check_selectlist","\"$element\" invalid");
}
}
}
##############
sub check_nonum {
local($nonum);
foreach $nonum (@_){
$nonum=$Form_Data->{"\$$nonum"};
if ($nonum =~/\d/){
push(@errorlog,$nonum,"check_nonum","contains numeric values");
}
}
}
##############
sub check_noletter {
foreach $noletter (@_){
$noletter=$Form_Data->{"\$$noletter"};
if ($noletter=~/[a-zA-Z]/){
push(@errorlog,$noletter,"check_noletter","contains letter(s)");
}
}
}
##############
sub check_numonly {
local(@numonly);
foreach $numonly (@_){
$numonly=$Form_Data->{"\$$numonly"};
if ($numonly=~/\D/){
push(@errorlog,$numonly,"check_numonly","contained non-numeric value");
}
}
}
##############
sub check_letteronly {
local(@letteronly);
foreach $letteronly (@_){
$letteronly=$Form_Data->{"\$$letteronly"};
@letteronly=split(//,$letteronly);
foreach $_ (@letteronly){
unless(/[a-zA-Z]/){
push(@errorlog,$letteronly,"check_letteronly","contained non-letter value");
last;
}
}
}
}
##############
sub check_notblank {
foreach $notblank (@_){
$fieldname=$notblank;
$notblank=$Form_Data->{"\$$notblank"};
if ( $notblank eq "" ) {
push(@errorlog,$fieldname,"check_notblank","element was blank");
}
}
}
1;