a more precise re for email addys
rbt
rbt at athop1.ath.vt.edu
Thu Jan 19 10:02:28 EST 2006
dave.brueck at gmail.com wrote:
> 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).
>
Just to follow-up on this. I found that doing something such as this
along with a more generic RE that the results are much better. Thanks
for the idea!
More information about the Python-list
mailing list