I was going to write a post here describing this function, why I wrote it, and what it does. But then I re-read the comments that I'd added to the function and the examples I'd included in the code and said "Hey, this is perfectly documented and doesn't need any further explanation."
/// Takes an email address and converts it to a normalized base form.
/// This is needed for some email addresses such as gmail where you can
/// add dots anywhere in the name as well as a + sign and tag anything
/// extra on to the email address.
/// Example email addresses to normalize:
/// These should all normalize to:
/// <param name="emailAddress">Any email address</param>
/// <returns>A modified/normalized email address or the original string</returns>
static public string NormalizeEmailAddress(string emailAddress)
// So far we only know about gmail.com that does this
string parts = emailAddress.Split('@');
// If there are more than 2 @'s in the address then this is an
// invalid email address so don't try and do anything to it.
if (parts.Count() == 2)
string beforeAtParts = parts.Split('+');
return beforeAtParts.Replace(".","") + "@" + parts;
Ironically I love this gmail feature and I use it all the time and I think that most people use it for the good. Unfortunately there's a small element of the population who will use this for multiple registrations on sites so that they can troll and spam so I am doing this conversion as a preventitive measure. Note that on the sites that I've implemented this on I've still allowed the users to register with any address that they want. However, when comparing a registration attempt against a site that does not allow registrations with the same email address then this will prevent multiple registrations by the same person.