| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Funcións úteis PHP

Page history last edited by Carlos Pena 14 years, 11 months ago

 

Comprobar formato de correo electrónico

function Comprobar_CorreoE($email) {
  // Primeiro, comprobamos que só existe un símbolo "@", e que alonxitude é correcta
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
     // correo inválido por número incorrecto de caracteres nunha parte, ou número incorrecto de @
     return false;
  } // if
  
  // divídese en partes por simplicidade
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++)
     if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
        return false;

  // revísase se o dominio é unha IP. Se non, debe ser un nome de dominio válido
  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
     $domain_array = explode(".", $email_array[1]);
     if (sizeof($domain_array) < 2)
        return false; // Non son suficientes partes ou seccións para ser un dominio
     for ($i = 0; $i < sizeof($domain_array); $i++)
        if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i]))
           return false;
  } // if
 
  return true;

} // Comprobar_CorreoE

 

Comments (0)

You don't have permission to comment on this page.