Validating an email address

Jean-Paul Calderone exarkun at divmod.com
Fri Dec 9 09:38:35 EST 2005


On Fri, 9 Dec 2005 11:10:04 +0000, Tom Anderson <twic at urchin.earth.li> wrote:
>Hi all,
>
>A hoary old chestnut this - any advice on how to syntactically validate an
>email address? I'd like to support both the display-name-and-angle-bracket
>and bare-address forms, and to allow everything that RFC 2822 allows (and
>nothing more!).
>
>Currently, i've got some regexps which recognise a common subset of
>possible addresses, but it would be nice to do this properly - i don't
>currently support quoted pairs, quoted strings, or whitespace in various
>places where it's allowed. Adding support for those things using regexps
>is really hard. See:
>
>http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
>
>For a level to which i am not prepared to stoop.
>
>I hear the email-sig are open to adding a validation function to the email
>package, if a satisfactory one can be written; i would definitely support
>their doing that.

The top part of <http://divmod.org/users/viewcvs.twistd/branches/exarkun/smtp-2418/quotient/proto/smtp.py?rev=7661&view=markup> contains a parser that, IIRC, is basically complete.  There are unit tests nearby, too.  The code is MIT licensed.

Jean-Paul



More information about the Python-list mailing list