Validating an email address

Jean-Paul Calderone exarkun at
Fri Dec 9 15:38:35 CET 2005

On Fri, 9 Dec 2005 11:10:04 +0000, Tom Anderson <twic at> 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:
>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 <> contains a parser that, IIRC, is basically complete.  There are unit tests nearby, too.  The code is MIT licensed.


More information about the Python-list mailing list