mee
mee

Reputation: 25

How can I allow email addresses from two different domains using Regex?

I've got an small form to download some stuff. But I don't want every buddy to download it. Only from 2 specific domains you can download the stuff. So I made an form with an email validation. But How can I add two Domains in the test of the email? What I was trying was:

$test = array(
'email' => '/^[\w.+-]{2,}\@[DOMAIN1][DOMAIN2]\.[a-z]{2,6}$/',
}

But that didn't worked …

Thanks for any help.

Upvotes: 1

Views: 106

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

By grouping the evaluation () and placing an or operator in it | you'll be able to handle either domain. See the below modified regex:

'email' => '/^[\w.+-]{2,}\@(DOMAIN1|DOMAIN2)\.[a-z]{2,6}$/',

Upvotes: 2

Related Questions