Improve flexibility of email validation in the ValidationHelper

* ValidationHelper.EmailRegEx can now be modified to suit the users needs
* Regex updated to be more inclusive - see https://html.spec.whatwg.org/#valid-e-mail-address
pull/7310/head
Oliver Cooper 5 years ago
parent 98b74aad91
commit 3f9cdce94b

@ -4,7 +4,9 @@ namespace Volo.Abp.Validation
{
public class ValidationHelper
{
private const string EmailRegEx = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
// Taken from W3C as an alternative to the RFC5322 specification: https://html.spec.whatwg.org/#valid-e-mail-address
// The RFC5322 regex can be found here: https://emailregex.com/
public static string EmailRegEx { get; set; } = @"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
public static bool IsValidEmailAddress(string email)
{
@ -13,7 +15,6 @@ namespace Volo.Abp.Validation
return false;
}
/*RFC 2822 (simplified)*/
return Regex.IsMatch(email, EmailRegEx, RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
}

Loading…
Cancel
Save