Sanitize and validate an email address


SUBMITTED BY: henry1874w

DATE: June 21, 2017, 11:47 p.m.

FORMAT: Text only

SIZE: 390 Bytes

HITS: 401

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <?php
  5. $email = "john.doe@example.com";
  6. // Remove all illegal characters from email
  7. $email = filter_var($email, FILTER_SANITIZE_EMAIL);
  8. // Validate e-mail
  9. if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  10. echo("$email is a valid email address");
  11. } else {
  12. echo("$email is not a valid email address");
  13. }
  14. ?>
  15. </body>
  16. </html>

comments powered by Disqus