Home / freesexchatmoblie / Validating email address with php

Validating email address with php

These days, users are expected to supply a valid email for just about everything, provided in exchange for the privilege of downloading software, learning more about the latest sales, and even for simply offering a comment to a favorite blogger's most recent entry.

For many users, admittedly myself included at times, the constant address beggaring has resulted in the prompt insertion of nonsensical, whimsical addresses such as "[email protected]", "23424!

Also, you must remember that email address standard was and can evolute, so you can't just type some "standard-valid" regexp once and for all times.

And you must remember that some concrete internet servers can fail some details of common standard and in fact work with own "modified standard". Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Nonetheless, to be sure there are times when the provision of a valid email address is an absolute necessity, not only for the site operator but also for the user.

How to check if an email address is valid in PHP: use one of the Filter functions, like this: $email1 = "[email protected]"; // not a valid email $email2 = "[email protected]"; // valid email $clean_email1 = filter_var($email1, FILTER_VALIDATE_EMAIL); // $clean_email1 = false $clean_email2 = filter_var($email2, FILTER_VALIDATE_EMAIL); // $clean_email2 = [email protected] The Filter extension was new in PHP 5.2, but is one of the unsung heroes of the language.

It's rare for me to ever describe one approach as the "right" way to do something - but for validating data, Filter really is excellent, offering both validating and sanitising filters and generally making it super-easy to clean up incoming variables.

For example, it is often in the interests of both parties that a confirmation email is sent to a specific address whenever goods are purchased from the site.

A valid email address is also vital in the case that the user is signing up for an email-based service, such as a newsletter or alerts such as stock or weather notifications.


  1. Jan 4, 2016. Here's the absolute easiest way you can validate an email address using PHP. This tiny function takes advantage of the filter_var function in PHP. function valid_email$email { return.filter_var$email, FILTER_VALIDATE_EMAIL; } That said, you really don't even need the function wrapper if you can.

  2. Sep 13, 2017. Want to make sure the email addresses entered in your web form are valid? Here's how to validate email addresses for correctness with PHP.

  3. Example #1 Validating email addresses with filter_var. ?php $email_a = '[email protected]'; $email_b = 'bogus'; if filter_var$email_a, FILTER_VALIDATE_EMAIL { echo "Email address '$email_a' is considered valid."; } if filter_var$email_b, FILTER_VALIDATE_EMAIL { echo "Email address '$email_b' is.

Leave a Reply

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