How to validate an email address in PHP?

Spread the love

Sometimes, we want to validate an email address in PHP.

In this article, we’ll look at how to validate an email address in PHP.

How to validate an email address in PHP?

To validate an email address in PHP, we can use the filter_var function.

For instance, we write

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // ...
}

to call filter_var to check if $email is a valid email string by calling it with $email and FILTER_VALIDATE_EMAIL.

Conclusion

To validate an email address in PHP, we can use the filter_var function.

Leave a Reply

Your email address will not be published. Required fields are marked *