Skip to content
PHP Logo

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

The ereg function is deprecated in PHP and should not be used for email validation. Instead, it is recommended to use the filter_var function with the FILTER_VALIDATE_EMAIL flag to properly validate email addresses.

php
$email = "example@example.com";

if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}