0

I'm using RFC 5322's simplified regular expression in my application to validate any kind of possible email addresses:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

But, i noticed that the string test@test.t is valid for this regular expression (tested on RegExr):

enter image description here

According to IANA, none of the valid top-level domains contains only 1 character.

My real doubt is: is RFC 5322 a reliable source to get a email validation regex? May I use any other? Or test@test.t is really valid for some specific case?

  • There is no such thing as a valid email regex. Some come closer than others http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address – Eric J. Oct 09 '15 at 20:39
  • You want your regex to validate against tlds? That's not maintainable. – ergonaut Oct 10 '15 at 02:29
  • @ergonaut I don't know if i were clear, but with the RFC regex, the e-mail `test@test.t` is valid. My doubt is: can i allow an e-mail like that to be submitted and inserted in my database? Is that regex reliable? – undefined is our god Oct 14 '15 at 17:38
  • 4
    Ask yourself that. Is foo@bar.mom valid? Will you accept that? – ergonaut Oct 14 '15 at 18:15

0 Answers0