Php valid email regex

A classic question!

In PHP, you can use the following regular expression to validate an email address:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

This regular expression matches most common email address formats, including:

Here's a breakdown of the regular expression:

You can use this regular expression in PHP like this:

$email = '[email protected]';
if (preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $email)) {
    echo 'Valid email address!';
} else {
    echo 'Invalid email address!';
}

Note that this regular expression does not validate whether the email address actually exists or is in use. It only checks whether the format of the email address is valid.