What are the potential pitfalls of using the ereg function for email validation in PHP scripts?

The ereg function is deprecated in PHP and has been removed in newer versions. It is recommended to use the preg_match function instead for email validation. This will ensure that your code is compatible with the latest PHP versions and follows best practices.

$email = "test@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";
}