What are some common pitfalls when checking for field consistency, like email addresses, in PHP?

One common pitfall when checking for field consistency, like email addresses, in PHP is not using the appropriate validation function to ensure the input meets the required format. To solve this, use the filter_var() function with the FILTER_VALIDATE_EMAIL flag to validate email addresses.

$email = "example@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Email is valid";
} else {
    echo "Email is invalid";
}