CoderZone.org

Category: >> Perl Code >> Check For A Valid Email Address Bookmark and Share

<< lastnext >>

Snippet Name: Check For A Valid Email Address

Description: This function will check whether or not an email address is validly formatted.

Also see:
» Validate file extensions in upload...
» Sending Email With Perl
» Validate A URL
» Validate credit card numbers
» Validate email address #3
» Validate email address #2
» Validate email address #1

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: December 03rd, 2010

sub CheckEmail{
 
return 0 if $_[0] =~ 
/(?:[\.\-\_]{2,})|(?:@[\.\-\_])|(?:[\.\-\_]@)|(?:\A\.)/;
return 1 if $_[0] =~ 
/^[\w\.\-\_]+\@\[?[\w\.\-\_]+\.(?:[\w\.\-\_]{2,}|[0-9])\]?$/;
return 0;
}
 
if(ValidEmail('name@example.com'){
  print "Email Address Is Valid" 
}else{ 
  print "Not Valid"; 
}
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 13