With the 'extension' method:
public static class ScottGuExtensions
{
public static bool IsValidEmailAddress(this string s)
{
Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
return regex.IsMatch(s);
}
}
you can use the method like that:
string s = "someone@somewhere.com";
if (s.IsValidEmailAddress()) {
}
With the 'non-extension' method :
public static class ScottGuExtensions
{
public static bool IsValidEmailAddress(string s)
{
Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
return regex.IsMatch(s);
}
}
you can use the mode like that:
string s = "someone@somewhere.com";
if (ScottGuExtensions.IsValidEmailAddress(s)) {
}
Does it make sense?