Perl Monk, Perl Meditation | |
PerlMonks |
Item Description: Checks the validity of an email address (hence the name ;-)
Review Synopsis:
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).
#!/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 }
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Email::Valid
by KM (Priest) on Sep 13, 2000 at 19:12 UTC | |
by kilinrax (Deacon) on Sep 13, 2000 at 19:29 UTC | |
by KM (Priest) on Sep 19, 2000 at 06:37 UTC | |
by turnstep (Parson) on Sep 15, 2000 at 00:58 UTC | |
by Anonymous Monk on Jul 16, 2001 at 11:29 UTC | |
by Aristotle (Chancellor) on May 23, 2002 at 09:58 UTC |