Jump to content

návod Validacia emailovej adresy


leone1234

Recommended Posts

Validácia emailovej adresy

 

Zisti, či ma zadaný email správny tvar.

 

Ak ma email správny formát, funkcia vracia TRUE, v opacnom pripade FALSE.

<?php
function isValidEmail($email)
{
  $regexp1 = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$";
  $regexp2 = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";

  //skontroluje dovolenú dĺžku jednotlivých časti emailovej adresy
  if(!ereg("^[^@]{1,64}@[^@]{1,255}$",$email)) {
     return false;
  }

  return (eregi($regexp1,$email) || eregi($regexp2,$email)) ? true : false;
}
?>

 

Príklad použitia:

$email = "nieč[email protected]";
if(isValidEmail($email)) {
  echo "Emailova adresa ma spravny tvar.";
} else {
  echo "Chybna emailova adresa!";
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...