Created
June 28, 2017 15:09
-
-
Save l4sh/c418c21fbbda2cf5396c834fcf6111dc to your computer and use it in GitHub Desktop.
C# clean up 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
public static string CleanUpEmail(string emailString) | |
{ | |
emailString = emailString.ToLower(); | |
string normalized = emailString.Normalize(NormalizationForm.FormD); | |
StringBuilder resultBuilder = new StringBuilder(); | |
foreach (var character in normalized) | |
{ | |
UnicodeCategory category = CharUnicodeInfo.GetUnicodeCategory(character); | |
// Strip all characters except uper/lower case letters | |
if (category == UnicodeCategory.LowercaseLetter | |
|| category == UnicodeCategory.UppercaseLetter | |
|| character == '_' | |
|| character == '.' | |
|| character == '@') | |
{ | |
resultBuilder.Append(character); | |
} | |
} | |
return resultBuilder.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment