Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

7 views
Skip to first unread message

fuzzylollipop

unread,
Aug 16, 2006, 6:23:06 PM8/16/06
to
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.

Simon Forman

unread,
Aug 16, 2006, 7:09:39 PM8/16/06
to

Would email.Utils.parseaddr() fit the bill?

http://docs.python.org/lib/module-email.Utils.html#l2h-3944

HTH,
~Simon

Jean-Paul Calderone

unread,
Aug 16, 2006, 7:25:34 PM8/16/06
to pytho...@python.org

This is for RFC 2822 addresses.

http://divmod.org/trac/browser/sandbox/exarkun/smtp.py

Jean-Paul

Tim Williams

unread,
Aug 16, 2006, 7:48:05 PM8/16/06
to fuzzylollipop, pytho...@python.org
On 16 Aug 2006 15:23:06 -0700, fuzzylollipop <jarrod....@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 :)

Tim Williams

unread,
Aug 16, 2006, 7:55:00 PM8/16/06
to fuzzylollipop, pytho...@python.org
On 17/08/06, Tim Williams <t...@tdw.net> wrote:
> On 16 Aug 2006 15:23:06 -0700, fuzzylollipop <jarrod....@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.
>

This also makes interesting reading

http://www.regular-expressions.info/email.html

:)

0 new messages