jellyfin/MediaBrowser.Server.Implementations/Connect/Validator.cs

30 lines
1020 B
C#
Raw Normal View History

2014-11-16 20:44:08 +00:00
using System.Text.RegularExpressions;
2014-10-23 04:26:01 +00:00
namespace MediaBrowser.Server.Implementations.Connect
{
public static class Validator
{
2014-11-16 20:44:08 +00:00
static readonly Regex ValidEmailRegex = CreateValidEmailRegex();
2014-10-23 04:26:01 +00:00
/// <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()
{
2014-11-16 20:44:08 +00:00
const string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
2014-10-23 04:26:01 +00:00
return new Regex(validEmailPattern, RegexOptions.IgnoreCase);
}
internal static bool EmailIsValid(string emailAddress)
{
bool isValid = ValidEmailRegex.IsMatch(emailAddress);
return isValid;
}
}
}