Email address check function

Michael Ströder michael.stroeder at inka.de
Thu Dec 2 14:12:10 EST 1999


Gerrit Holl wrote:
> 
> I'm writing some CGI scripts and I want the user to fill in their real 
> email address. Checking this is more difficult than just look if it 
> contains an '@'.
> There must be at least one '.' after the '@' but there must be non-'@' 
> chars before and after every '.', no white space, etc.

How about this:
re.compile(r"^([\w at .=/_-]+)@([\w-]+)(\.[\w-]+)*$").match(emailaddress)

Well, I think there are some real regex gurus here which can improve my
weak guess and provide even stricter patterns.

> There must be an RFC for this

RFC 822?

You could also check if A or MX records exist for the domain part of the
email address in the DNS. Watch out for dnslib.py in your Python 1.5.2
distr. under demos(?). This does not prevent people from entering
bill.gates at hotmail.com.

You could send some access code via email for further access to your
system.

Ciao, Michael.




More information about the Python-list mailing list