0

I have looked through questions asked in Stack Overflow to answer my question, but haven’t come up with a solution. I am needing to validate email addresses with the Amazon email service validation in mind. Here are the rules I am trying to follow:

  1. Dash cannot be preceded or followed by a period. Example: .- or -.
  2. Dash cannot be at the beginning of the domain. Example: grant.fox@-abcfinancial.com
  3. Dash cannot be at the end of the domain. Example: grant.hill@abc.com-

So far this is what I have come up with:

/^[a-z0-9!#$%&'*+=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9]))+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.[A-Z]{2,6}$/
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
BrianGray
  • 11
  • 1

1 Answers1

0

Thanks to ctwheels we have an answer

^(?!.*(?:\.-|-\.))[^@]+@[^\W_](?:[\w-]*[^\W_])?(?:\.[^\W_](?:[\w-]*[^\W_])?)+$

BrianGray
  • 11
  • 1