user747796
user747796

Reputation: 43

Reg expression for certain letters in a email

In this expression below it checks for a valid email. My question is how can I check for ppl|pplweb is in the email address after the @ sign

!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)

Thanks

Upvotes: 0

Views: 72

Answers (1)

Andreu Ramos
Andreu Ramos

Reputation: 2908

you can split your $email var in 2 components of the array separating it by the @ sign

$splitted_email = explode('@',$email);

and then search by the ppl/pp/web patterns in the first component of your array

preg_match('(/ppl|pplweb/i)',$splitted_email[1]);

this way, maybe the code is a bit longer but short regular expressions are better to mantain.

Upvotes: 1

Related Questions