Created
January 10, 2012 08:06
-
-
Save huseyinyilmaz/1587767 to your computer and use it in GitHub Desktop.
Normalize email
This file contains hidden or 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 normalize_email(self, email): | |
""" | |
Normalazing email addres. An email address | |
has following properties: | |
1) It is case-insensitive | |
2) "." characters on username part of email address is ommited. | |
For instance [email protected] and [email protected] are the | |
same address. | |
3) Anything after "+" sign is ommited. [email protected] and | |
[email protected] are same email address. | |
This code does not really validate email address. Make sure given | |
string is a valid email address before using this. | |
If You are using django you can use | |
django.core.validators.validate_email | |
for validation. | |
""" | |
# remove spaces at start and end of the and lowercase email address | |
email = email.strip().lower() | |
# split email into username and domain information | |
username, domain = .split('@') | |
# remove . characters from username | |
username = username.replace('.', '') | |
#remove everything after + | |
username = username.split('+')[0] | |
return "%s@%s" % (username, domain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regarding rule #2: This only applies to gmail.com/googlemail.com, just in case someone comes across this