reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

Please fix your broken email regex!

Open RandalSchwartz opened this issue 4 years ago • 12 comments

No, please don't use this so-called "regex email validation".

I can think of a few email addresses that are perfectly valid that do not match that regex. When you want to validate an email address, please do not use a hand-rolled (or even copy-n-pasted) regex.

Instead, use (Dart) https://pub.dev/packages/email_validator (or Perl) https://metacpan.org/pod/Mail::RFC822::Address, which properly implements the RFC822 (et. seq.) address according to the rules in the RFC.

(Jokingly...) Or, cut-n-paste this one (and only this one): http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html. Don't forget to remove the newlines from that 1400-char monster. :)

RandalSchwartz avatar Jun 18 '21 22:06 RandalSchwartz

Hi @RandalSchwartz,

Sorry for the late answer and thanks for your advice. I will take a closer look at your proposition. I will let you know when it is included in future releases.

Best regards

joanpablo avatar Jun 24 '21 14:06 joanpablo

Hi @RandalSchwartz,

could you give some examples of valid emails that do not match the current regex implementations (just to create some unit tests)

Thanks best regards

joanpablo avatar Jul 06 '21 07:07 joanpablo

@joanpablo I think the list could be taken from here https://github.com/fredeil/email-validator.dart/blob/master/test/email_validator_test.dart#L6

vasilich6107 avatar Jul 19 '21 19:07 vasilich6107

https://regex101.com/r/HN6jk7/1

vasilich6107 avatar Jul 19 '21 19:07 vasilich6107

Thanks @vasilich6107 I will take a look

joanpablo avatar Jul 21 '21 10:07 joanpablo

Any update on this ? I think it's a valid concern. I would rather depend on a single lib that validates email without regexp and with a pretty extensive test suite than an obscure regexp string copy pasted from who knows where.

tlvenn avatar Sep 08 '22 04:09 tlvenn

Validating domain names and Email Addresses has always been a tricky issue since time immemorial. I have discussed the issues surrounding the same in a blog. If interested, please do check out. What is the ultimate goal of the Domain Name and Email ID Validation?

thinktrans avatar Oct 05 '22 05:10 thinktrans

Hi I am on Angular

And using the below regex:

'^[a-z0-9]+([._-]?[a-z0-9]+)+@[a-z0-9]+([._-]?[a-z0-9]+)+\\.[a-z]{2,3}$'

But its not fulfilling my requirement, my requirement is below:

saa5@me-d_d_u.co

please anyone tell me, why this regex is not working for my above mentioned case.

Regards Babar Ali Shah

babaralishah avatar Oct 06 '22 07:10 babaralishah

This is not stackoverflow, spamming your problems in unrelated issues will get you blocked.

kuhnroyal avatar Oct 06 '22 08:10 kuhnroyal

Hi and thanks for highlighting the need for a new email validation approach. I believe you are right and we need a new implementation that doesn't use Regex. I will start working on this as soon as possible. Any PR is also weel received.

Thanks

joanpablo avatar Oct 06 '22 13:10 joanpablo

I gave you the solution already. Use package:email_validator. Done.

RandalSchwartz avatar Oct 09 '22 18:10 RandalSchwartz

Just check for the existence of @. https://mdswanson.com/blog/2013/10/14/how-not-to-validate-email-addresses.html After 10 years still valid.

Kiura avatar Nov 13 '23 21:11 Kiura