Anyone have a link handy to an RFC 821 compliant email address regex for Python?

Tim Williams tim at tdw.net
Wed Aug 16 19:48:05 EDT 2006


On 16 Aug 2006 15:23:06 -0700, fuzzylollipop <jarrod.roberson at gmail.com> wrote:
> I want to do email address format validations, without turning to ANTLR
> or pyparsing, anyone know of a regex that is COMPLIANT with RFC 821.
> Most of the ones I have found from google searches are not really as
> robust as I need them to be.
>

RFC 2821 and 2822 specify the format for email addresses.

Contrary to popular belief,  just about all characters are valid and
this makes validating an address format very difficult.  Also,  just
because an email address is in the correct format doesn't mean its a
real or valid address.

http://en.wikipedia.org/wiki/E-mail_address has a short overview

>From experience,  you might be better off not putting too much energy
into this,  and maybe instead just do a basic template validation eg:
some text followed by @ followed by some text which when split by '.'
gives at least 2 parts.  In addition a DNS MX record lookup will tell
you if the domain part is capable of receiving email,  the address
can't be valid (for internet transmission) without MX records.

If you want to take it a step further, you can also query the
server(s) pointed to in the MX records,  but this takes time, and is
not accurate.  Some domains have catchalls,  and others like yahoo
don't refuse an address until after a whole email has been received.

HTH :)



More information about the Python-list mailing list