Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Email::Valid

by kilinrax (Deacon)
on Sep 09, 2000 at 18:33 UTC ( #31747=modulereview: print w/ replies, xml ) Need Help??

Item Description: Checks the validity of an email address (hence the name ;-)

Review Synopsis:

Email::Valid


Description

Checks an email address for rfc822 compliance, and, optionally, can also perform an mx check on the domain.
It's worth pointing out here again that attempting to check an email address with a regexp is a very bad idea (see merlyn's reaction to one such attempt, or the explanation of it from perlfaq 9).

Requirements

Who Should Use It?

  • Anyone who wants a simple and fairly reliable check of an email address submitted via a form over the web.

Any Bad Points?

  • Not a 100% reliable method of verifying an email address (can't be done, except by sending mail to it).
  • Requests can sometimes take a while to process.

Example

#!/usr/bin/perl require 5; use strict; use Email::Valid; use vars qw($addr $email); if (@ARGV) { foreach $email (@ARGV) { eval { unless ($addr = Email::Valid->address( -address => $email, -mxcheck => 1 )) { warn "address failed $Email::Valid::Details check."; } }; warn "an error was encountered: $@" if $@; } } else { print <<EOF; Usage: $0 [email(s)] Synopsis: checks email address is rfc822 compliant, and performs an mx + check on the domain. EOF }

Comment on Email::Valid
Download Code
RE: Email::Valid
by KM (Priest) on Sep 13, 2000 at 19:12 UTC
    Here is a patch I added to Email::Valid to help with AOL addresses. I submitted it to the author, but don't think it was added. Someone else may find it useful. The issue I had was people from AOL putting in email addresses as me@aol, since many of them seem to think AOL *is* the internet. The project I was working on needed to validate email addresses for a mailing list, so Email::Valid was great, and adding this patch helped me a bit.

    --- Valid.pm Fri Jul 9 01:34:55 1999 +++ Valid.pm.new Wed May 10 11:03:20 2000 @@ -186,6 +186,9 @@ my $self = shift; my $addr = shift; + # Since many AOL users think AOL _is_ the internet + # they sometimes leave off the .com, so let's help them + $addr .= ".com" if $addr =~ /aol$/i; $addr =~ s/\s+//g if $addr =~ /aol\.com$/i; $addr =~ s/,/./g if $addr =~ /compuserve\.com$/i; $addr; @@ -431,7 +434,9 @@ Specifies whether calls to address() should attempt to correct common addressing errors. Currently, this results in the removal of spaces in AOL addresses, and the conversion of commas to periods in -Compuserve addresses. The default is false. +Compuserve addresses. This will also tack on a .com to AOL addresses +which fail to have them, ie. user@aol which is common for AOL users t +o +do. The default is false. =item fqdn ( <TRUE>|<FALSE> )

    Cheers,
    KM

      Actually, that code has been included. Obviously someone else did find it useful ;-)
      Just use the -fudge parameter:
      #!/usr/bin/perl -w require 5; use strict; use Email::Valid; my $email = 'demon warez dood@aol.com'; eval { if (my $addr = Email::Valid->address( -address => $email, -mxcheck => 1, -fudge => 1 )) { print "$addr OK\n"; } else { print "$addr failed $Email::Valid::Details check.\n"; } }; warn "an error was encountered: $@" if $@;
        No, that is another feature. That one cleans up spaces and such, my patch fixes foo@aol to foo@aol.com... both useful :)

        Cheers,
        KM

      Hrmm..you must be getting some of the smarter AOL users. *grin*. I am lucky if I can get them to give anything but "joe2345" or "lammo234" - an @ sign? What's that? I've written some code that actually checks the IP for people like this and appends "@aol.com" if that is where they are indeed connecting to the Internet through :)

        The question really is: do you want to take the time to send these blokes anything?
      The reason is probably that this is not the module's aim. If I were writing an SGML parser, I wouldn't add workarounds to deal with the commonly malformed HTML found out there on the web. Similarly, the HTML::Parser module's docs note that it's not a generic SGML parser because it does include such kludges. In your case, I'd pass Email::Valid the address and given failure, check if it's kludgable and possibly pass it back in for another check.

      Makeshifts last the longest.

Back to Reviews

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: modulereview [id://31747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-18 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (60 votes), past polls