When I looked at the e-mail validation function of the standard Perl checkout script, I saw why this happened. I changed the regexp, so that it will validate e-mail addresses starting with digits:
- Code: Select all
sub invalidE {
my ($szEmail) = @_;
my ($user, $host);
$szEmail =~ tr/A-Z/a-z/;
if ($szEmail =~ /\s/) { return 1; }
($user, $host) = split (/\@/, $szEmail);
if ($host =~ /compuserve/i) { ; }
else {
if (! $user =~ /\D/) { return 1; }
if (! $host =~ /\D/) { return 1; }
# if (substr ($user,0,1) !~ /[a-z]/) { return 1; }
if (substr ($user,0,1) !~ /[a-z0-9]/) { return 1; }
}
if ($szEmail =~ /\w+\@[\w|\.]/) { return 0; }
else { return 1; }
}
If you wish, you could also use the following elegant function, which I found at the ActiveState site:
- Code: Select all
sub ValidEmailAddr { #check if e-mail address format is valid
my $mail = shift; #in form name@host
return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ ); #characters allowed on name: 0-9a-Z-._ on host: 0-9a-Z-. on between: @
return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/); #must start or end with alpha or num
return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ ); #name must end with alpha or num
return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ ); #host must start with alpha or num
return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g ); #pair .- or -. or -- or .. not allowed
return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g ); #pair ._ or -_ or _. or _- or __ not allowed
return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ ); #host must end with '.' plus 2 or 3 alpha for TopLevelDomain (MUST be modified in future!)
return 1;
}
