1

I know this is a common question, but I still can't seem to find a great regular expression to use when validating email addresses. What is the best regular expression you have or have seen for validating emails with below condition?

  • email constructor: first_element@second_element
  • first_element: the first element (user name part)
  • second_element: the second element (domain part)

The condition is: All the element not contain spaces, control characters, or non-ASCII characters. thanks

Dinh Hoa
  • 13
  • 3
  • Please, have a look at these sites: [TLD list](https://www.iana.org/domains/root/db); [valid/invalid addresses](https://en.wikipedia.org/wiki/Email_address#Examples); [regex for RFC822 email address](http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html) – Toto Feb 11 '20 at 10:03

1 Answers1

0

Try

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

Explanation

Flow

Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55