Ver Mensaje Individual
  #9 (permalink)  
Antiguo 08/10/2010, 15:22
Avatar de pateketrueke
pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Pequeñísimo aporte: función para validar emails

Cita:
Iniciado por Hidek1 Ver Mensaje
por lo personal.. no uso filter_var ya que al hacer pruebas con este te das cuenta de lo poco confiable que es..
+1

de algún modo por eso me fascinan las expresiones regulares, al menos dicho así son mas fiables que usar filter...

aquí mi sencillo aporte:
Código PHP:
/**
 * Validar E-mail
 *
 * @param  string  $text  Cadena
 * @param  boolean $multi Emails multiples?
 * @param  boolean $check Emplear checkdnsrr()?
 * @return boolean
 */
function is_email($text$multi FALSE$check FALSE)
{
    static 
$expr '/^([\w\+\-:]+)(\.[\w\+\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i';
    
$text preg_split('/[,;\|]+/', (string) $text);

    if ( ! 
$multi && (sizeof($text) > 1)) return FALSE;
    elseif (empty(
$text)) return FALSE;

    foreach (
$text as $value)
    {
        if ( ! 
preg_match($expr$value)) return FALSE;
        elseif (
$check === TRUE && ! checkdnsrr(substr($valuestrpos($value'@') +1), 'MX')) return FALSE;
    }
    return 
TRUE;

__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.