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 [EMAIL PROTECTED]@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).

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to