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
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|