Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 40 lines (24 sloc) 1.081 kB
c0eba03 Email is a common-enough theme in Perl, so I split it off of the How …
Jason Crome authored
1 =head1 Email Addressing, Processing, and Handling
2
3 =head2 How do I see if an email address is valid?
4
5 In general, you can't. There are several methods available to see
6 if it looks reasonable, but there is no way to determine if an
8b659d6 @petdance fixing whitespace
authored
7 address is actually deliverable without actually attempting delivery.
c0eba03 Email is a common-enough theme in Perl, so I split it off of the How …
Jason Crome authored
8
9 Using regular expressions:
10
11 # Match basically blah@blah.blah
12 if ( $addr =~ /^\S+\@\S+\.\S+$/ ) {
13 print "Looks OK";
14 }
15
16 If you're doing any real work, you may wish to look to one of
17 the modules available on L<http://search.cpan.org>, such as:
18
19 =over 4
20
21 =item C<Email::Address>
22
23 =item C<Email::Valid>
24
25 C<Email::Valid> makes it easy to determine if an email address is
26 well-formed:
8b659d6 @petdance fixing whitespace
authored
27
c0eba03 Email is a common-enough theme in Perl, so I split it off of the How …
Jason Crome authored
28 use Email::Valid;
29
30 print ( Email::Valid->address( 'someone@gmail.com' ) ? 'Yes' : 'No' ); # prints Yes
31 print ( Email::Valid->address( 'someone#gmail.com' ) ? 'Yes' : 'No' ); # prints No
32
33 C<Email::Valid> can also tell you why an address is invalid:
8b659d6 @petdance fixing whitespace
authored
34
c0eba03 Email is a common-enough theme in Perl, so I split it off of the How …
Jason Crome authored
35 print "Invalid address: $Email::Valid::Details \n"
36 unless Email::Valid->address( 'you#foo.bar' );
37
38 =back
39
Something went wrong with that request. Please try again.