Created
April 22, 2012 03:49
-
-
Save christophchamp/2448351 to your computer and use it in GitHub Desktop.
Vet a given E-mail address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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