0

I've got a basic email regular expression, however I have a requirement that the it also validates the length of characters is not more that 254 (as per email standards?

How would I make sure that it does not match emails longer than 254 characters long?

^[_A-Za-z0-9-+]+(\.[_A-Za-z0-9-+]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})$

http://regexr.com/3fsck

aaaidan
  • 305
  • 3
  • 12

1 Answers1

1

Put ^(?=.{0,254}$) at the start:

^(?=.{0,254}$)[_A-Za-z0-9-+]+(\.[_A-Za-z0-9-+]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})$

Demo: http://regexr.com/3fscq

Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40