2

I want to validate email format with name that can handle both patterns

Valid

  1. [email protected]
  2. test user <[email protected]>
  3. test user<[email protected]>
  4. "test user" <[email protected]>
  5. "test user"<[email protected]>

Invalid

  1. "test user" <[email protected]
  2. "test user" [email protected]>
  3. test user <[email protected]
  4. test user [email protected]>
  5. "test user <[email protected]>
  6. test user" <[email protected]>
  7. "test user" [email protected]

here's my progress: https://regex101.com/r/Q00McL/1

sic
  • 69
  • 1
  • 3

1 Answers1

0

Why are items 4. "test user" [email protected] (valid) and 7. "test user" [email protected] (invalid) the same?

If you want "test user" [email protected] to be valid use this pattern:

^(?:(?:"[^"\r\n]+"|\w+(?: +\w+)*) *)?\w+@[^<>\s@]+\.\w{2,3}$

On the contrary, if "test user" [email protected] should be invalid use:

^(?:(?:"[^"\r\n]+"|\w+(?: +\w+)*)*)?\w+@[^<>\s@]+\.\w{2,3}$
DVN-Anakin
  • 1,549
  • 1
  • 8
  • 12