Validating Email Addresses

Validating Email Addresses – The Daily WTF:

The format for e-mail addresses is specified in a number of RFCs; it’s a pet peeve of mine when people “validate” away perfectly valid addresses, for instance: websites that think all domains end in .com, .net, .edu, or .org; and agents that refuse to transfer mail with a + in the local-part. To that end, I wrote my own regular expression that (I believe) follows the specification, which I’ll share below.

here’s what I use (in perl). there are a few things in the RFC it doesn’t handle, but they’re things nobody seems to really use these days. From my testing, almost no failures of good addresses, and very low rates of bad ones going in (I’d err on the side of letting a bad one through, FWIW, to be caught by a later test like MX resolution).

if (! ($addr =~ /^[a-z0-9+_.-]+@[_a-z0-9.-]+.[a-z0-9]{2,5}$/i)

|| ($addr =~ /@./)

|| ($addr =~ /@.*../) )


} else {