Johan Pietersen
Johan Pietersen

Reputation: 13

Regular Expression for multiple specific-domain email addresses (separated)

Good day,

I'm looking for a regular expression that would validate the following email addresses:

[email protected], [email protected]

So far, I have this:

^([\w+-.%]+@domain\.com,?\s*)+$

It should not return anything in case of:

[email protected]@domain.com     or

[email protected] [email protected]
  1. It should also return a result if a ; is entered.
  2. Also, is there a way to ensure a result will be returned only when there is a single @ in an address?

Any help would be appreciated.

Upvotes: 1

Views: 550

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626932

The regex you are looking for is ^(?>\b[\w+-.%]+@domain\.com(?:[,;]\s*)?)+\b$.

I am using atomic grouping with (?>...) so that no backreferences are created.

Result is as you request: [email protected], [email protected]

Also tested with Expresso.

Upvotes: 0

Related Questions