Created
May 16, 2012 12:05
-
-
Save jarrettmeyer/2709855 to your computer and use it in GitHub Desktop.
Email validation - the point is to show that the extension method doesn't actually do anything. The real logic is in the validator class.
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
public class EmailValidator | |
{ | |
private const string PATTERN = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$"; | |
public static bool IsValid(string s) | |
{ | |
if (string.IsNullOrEmpty(s)) | |
return false; | |
// Regex from http://www.regular-expressions.info/email.html | |
bool isMatch = Regex.IsMatch(s, PATTERN, RegexOptions.IgnoreCase); | |
return isMatch; | |
} | |
} | |
public static class StringExtensions | |
{ | |
public static bool IsEmail(this string str) | |
{ | |
return EmailValidator.IsValid(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment