Search code examples
phpstrpos

How to find out if an email address starts with something and ends with a domain


Take this email for example

$email = "[email protected]";

I need to use php to find out if an email starts with outlook_ AND ends with @outlook.com. Since 75AA07B2DF4B8074 will always be different. I've got the beginning but not sure how to get the end as well.

if (strpos($email, 'outlook_') === 0) {

}

Solution

  • preg_match('/^outlook_.*@outlook\.com$/', $email);