a more precise re for email addys
dave.brueck at gmail.com
dave.brueck at gmail.com
Wed Jan 18 16:50:22 EST 2006
Does it really need to be a regular expression? Why not just write a
short function that breaks apart the input and validates each part?
def IsEmail(addr):
'Returns True if addr appears to be a valid email address'
# we don't allow stuff like foo at bar@biff.com
if addr.count('@') != 1:
return False
name, host = addr.split('@')
# verify the hostname (is an IP or has a valid TLD, etc.)
hostParts = host.split('.')
...
That way you'd have a nice, readable chunk of code that you could tweak
as needed (for example, maybe you'll find that the RFC is too liberal
so you'll end up needing to add additional rules to exclude "bad"
addresses).
More information about the Python-list
mailing list