Validating EMailAdresses for syntactical correctness

Mark McEahern marklists at mceahern.com
Thu Jan 24 13:26:36 EST 2002


Michael W. Dietrich wrote:
> Has anyone ever written a class, function or regular expression, that
> validates EMail-Addresses (e.g. such entered in Web Forms) for their
> syntactical correctness? If so, is that algorithm available? Where?

Hmm, have you tried google?  There may not be such in Python, but I'm sure
you can translate whatever samples you find.  The basic idea is to use
regular expressions, right?  I remember seeing an approach that explicitly
provided different levels of strictness.  Something like this:

Level 1:  Just make sure you have something at something

Level 2:  Make sure you have something at something.something

Level 3:  Make sure the tld is valid.

Level 4:  Make sure the domain is valid (whois, ping, etc)

Level 5:  Make sure the address itself is valid (resolve the mx record and
test the address via smtp).

Cheers,

// mark





More information about the Python-list mailing list