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

  • Whenever you search in PBworks or on the Web, Dokkio Sidebar (from the makers of PBworks) will run the same search in your Drive, Dropbox, OneDrive, Gmail, Slack, and browsed web pages. Now you can find what you're looking for wherever it lives. Try Dokkio Sidebar for free.

View
 

Funcións úteis PHP

Page history last edited by Carlos Pena 14 years, 4 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.