[thelist] testing for email address in perl

Paul Cowan paul at wishlist.com.au
Mon Jan 14 00:14:12 CST 2002


Kristy Frey wrote:

> I just had it pointed out to me in another thread that 
> foo at foo.info is a valid email address
> format
> 
> So perhaps, with .xxxx addresses, we need to change it to:
> 
> m/(\w[-.\w]+\@[-.\w]+\.\w{2,4})\W/

Well, yeah... until .museum comes along (soon!).

May as well summarise this in a:

<tip type="Email Validation" author="Paul Cowan">
Don't overvalidate email addresses. Assuming that the 
last part of an email address is 3 characters only (.com,
.net, .org) is a sure way to annoy your international
customers (.au, .br, .za...). But just because all the
current domains are 2-3 characters [1] doesn't mean that all
future ones will be: in fact, .info is already (partially)
live -- and .aero and .coop are on the way... as is the
rather enormous .museum. Perhaps you're better off just
checking the pattern, and not stressing over the length.

What's more, email addresses don't have to be alphabetic.
paul at 10.1.1.1 is a valid email address [2] -- you don't just
have to use domain names.

Oh, and so is paul at 167837953, while we're at it [3].

Anyway, if you're really determined to make it check for
a valid email, it's trivial for a user to enter
kljsdfgklsiweu at fdssdfsdf.com...

My advice: don't worry too much. Check for an @, that
will generally do.

[1] actually, they're not all 3 characters: .arpa has been 
valid for yonks.

[2] well, one on a non-routable IP -- but you get the idea.

[3] See http://www.pc-help.org/obscure.htm to see why.
</tip>




More information about the thelist mailing list