Posted By

frvalois on 09/26/12


Tagged

form email validation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

3polars


Form validation - Email validation


 / Published in: PHP
 

Return false if the email is valid - True if it's not

  1. // Use this
  2. $email_is_valid = valid_email($email, $db);
  3.  
  4. // Function
  5. function valid_email ($email, $db) {
  6.  
  7. $r_email = $db->prepare('SELECT COUNT(id) FROM inscriptions WHERE email = ?');
  8. $r_email->execute(array($email));
  9. $r_email_count = $r_email->fetchAll();
  10.  
  11. if ($r_email_count[0][0] == 0):
  12.  
  13. if (!filter_var($email, FILTER_VALIDATE_EMAIL)):
  14. return true;
  15. else:
  16. return false;
  17. endif;
  18.  
  19. else:
  20. return true;
  21. endif;
  22. }

Report this snippet  

You need to login to post a comment.