How can regular expressions (regex) be effectively used to validate email inputs in PHP registration scripts?

Regular expressions can be effectively used to validate email inputs in PHP registration scripts by checking if the input follows the standard email format. This can help ensure that users enter a valid email address during the registration process, reducing errors and improving data quality.

$email = "example@example.com";

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";
}