Z.ExtensionMethods icon indicating copy to clipboard operation
Z.ExtensionMethods copied to clipboard

.IsValidEmail() reporting incorrect results

Open jasenf opened this issue 5 years ago • 4 comments

String extension method .IsValidEmail() is incorrectly reporting e-mails such as

[email protected]

as invalid. This is a valid RFC e-mail address, and one recommended by Google to alias existing inboxes.

jasenf avatar Oct 15 '19 21:10 jasenf

Hello @jasenf ,

Do you have a proposal to the Regex we should use? Last time I made a research about it, pretty much all regex has some flaw and it seems there is no consensus about which Regex to use.

Best Regards,

Jonathan


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan avatar Oct 16 '19 13:10 JonathanMagnan

I think it's fine as-is if you just allow the + sign.

jasenf avatar Oct 16 '19 15:10 jasenf

We will try to review it soon by using the syntax from here: https://en.wikipedia.org/wiki/Email_address

It will not be perfect but we will change the regex to at least contains printable characters (which contains the plus sign)

JonathanMagnan avatar Oct 17 '19 13:10 JonathanMagnan

If you really want to make it validate email addresses, RegularExpressions probably isn't the way to go. The simplest way to cover everything would probably be to just try creating a new MailAddress object and catch if an exception is thrown OR re-implement the code that does the email address validation from the .NET framework (https://github.com/microsoft/referencesource/blob/master/System/net/System/Net/mail/MailAddressParser.cs)

dmarciano avatar Nov 27 '19 13:11 dmarciano