|
Description:
This code Perl snipet is intended to check valid e-mail address, code is easy to understand because composed by step by step regex rather than full one line complicated regex, thus its makes each step may be easily modified as needed.
Contact me: tbyte@bolehmail.com
Usage: Text Source
sub ValidEmailAddr {
my $mail = shift;
return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
return 1;
}
The license for this recipe is available here.
Discussion:
As ICANN already assigned Top Level Domain name more than 3 characters, user must be modified the last code fragment.
|