Skip to content

Instantly share code, notes, and snippets.

@huseyinyilmaz
Created January 10, 2012 08:06
Show Gist options
  • Save huseyinyilmaz/1587767 to your computer and use it in GitHub Desktop.
Save huseyinyilmaz/1587767 to your computer and use it in GitHub Desktop.
Normalize email
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)
@mpldr
Copy link

mpldr commented Mar 30, 2022

Regarding rule #2: This only applies to gmail.com/googlemail.com, just in case someone comes across this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment