How to validate an email in PHP?

Spread the love

Sometimes, we want to validate an email in PHP.

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

How to validate an email in PHP?

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

For instance, we write

filter_var($email, FILTER_VALIDATE_EMAIL);

to call filter_var with $email and FILTER_VALIDATE_EMAIL to check if the $email string is a valid email address string.

If it returns false, then it’s not a valid email string.

Conclusion

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

Leave a Reply

Your email address will not be published.