Skip to content

Instantly share code, notes, and snippets.

@christophchamp
Created April 22, 2012 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophchamp/2448351 to your computer and use it in GitHub Desktop.
Save christophchamp/2448351 to your computer and use it in GitHub Desktop.
Vet a given E-mail address
def vet_email(email_address):
"""Vet email addresses. The local part (the part before the '@') must not
exceed 64 characters and the domain part (after the '@') must not
exceed 255 characters. The entire email address length must not exceed
320 characters.
"""
local_part = re.sub(r'^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$', '\\1', email_address)
domain_part = re.sub(r'^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$', '\\2', email_address)
if len(local_part) > 64:
return False
if len(domain_part) > 255:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment