Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2.  
  3. function validar_email($mail){
  4.     if(preg_match("#^[A-Za-z0-9\._+-]+[@]{1}[A-Za-z0-9\.|-|_]*[.]{1}[a-z]{2,5}$#",$mail)){
  5.         return true;
  6.     }
  7.     return false;
  8. }
  9.  
  10. // tests
  11.  
  12. $emails = array('luis@teste.com', '@t.com', 'exemplo@12.c', 'teste_12-3@subdominio1.dominio.com.br');
  13.  
  14. foreach ($emails as $email)
  15. {
  16.     echo $email . ' ';
  17.     if (validar_email($email))
  18.         echo "<span style='color: green'>Email valido!</span>";
  19.     else
  20.         echo "<span style='color: red'>Email invalido!</span>";
  21.     echo "<br />";
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement