Search code examples
regexsubdomainemail-validation

REGEX to match domain in email addresses


I'm currently using this very relaxed REGEX to validate email addresses:

(/(.+)@(.+)\.(.+){2,}/.test(emailAddress)
  1. I believe that it only allows min1_allowsDots@min1_allowsDots.min2 - is this correct?

  2. How should I modify it to match only a particular domain - anything@ onlythisdomain.com?

TIA!

iSofia


Solution

  • (.+)@onlythisdomain\.(.+){2,}
    

    This should do it.If .com is also fixed use

    (.+)@onlythisdomain\.com