You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1020 B
30 lines
1020 B
using System.Text.RegularExpressions;
|
|
|
|
namespace MediaBrowser.Server.Implementations.Connect
|
|
{
|
|
public static class Validator
|
|
{
|
|
static readonly Regex ValidEmailRegex = CreateValidEmailRegex();
|
|
|
|
/// <summary>
|
|
/// Taken from http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static Regex CreateValidEmailRegex()
|
|
{
|
|
const string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
|
|
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
|
|
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
|
|
|
|
return new Regex(validEmailPattern, RegexOptions.IgnoreCase);
|
|
}
|
|
|
|
internal static bool EmailIsValid(string emailAddress)
|
|
{
|
|
bool isValid = ValidEmailRegex.IsMatch(emailAddress);
|
|
|
|
return isValid;
|
|
}
|
|
}
|
|
}
|