Tuesday, 06 January 2009
   
Home arrow Tutorial  
 
Home
Supporto
Contattaci
Categorie Script
RSS Media Grabber Video & Foto Divertenti Storie di Vita (Flash) Video: Ricerca & Download Script Download Video Nazioni in Vendita Script per Sondaggi Host per File wap Script Creazione SlideShow Script PhotoCube Script "Make Confessions" Script Spartiti Chitarra Crea Smile Personalizzati URL Brevi & Sottodomini Script Gioco Hot Or Not Metti il Tuo Testo Sulle Img Host & Watermark Img Salva i Tuoi Preferiti Online Componenti Joomla Script a Basso Costo
Partners
StileGames
Php Tutorial
 
 
   
 
E-mail Validation with PHP Print E-mail

This tutorial will show you how to check to see if an E-mail address is valid.

When you register on at a website, the site normally checks if the e-mail address that you enter is in a valid format. This is done by using what called a Regular Expression. What we need to do is check if a string (eg $email) matches the regular expression:

ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email);

At the moment that only checks the string ($email), but does not does not output anything.So next we need to write an IF statement that returns a boolean value, if the string does not match the regular expressions.

if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
{
return FALSE;
}

That is the basic validation bit, but now we can do even more validation. What we will do next is check the domain name after the @ is a real domain name. (We do this by checking if an MX record exists for that domain name and then we check if port 25 is open for that domain name, which makes sure that the domain name is in use.)

list($Username, $Domain) = split("@",$email);
if(getmxrr($Domain, $MXHost))
{
return TRUE;
}
else
{
if(fsockopen($Domain, 25, $errno, $errstr, 30))
{
return TRUE;
}
else
{
return FALSE;
}
}

Now to finish it all off we put those last two pieces of code togther in a function, so we can re-use again and again. If you are not understanding the code, ignore everything we said above and copy-paste this code on the top of your PHP code.

function checkEmail($email)
{
if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
{
return FALSE;
}

list($Username, $Domain) = split("@",$email);

if(getmxrr($Domain, $MXHost))
{
return TRUE;
}
else
{
if(fsockopen($Domain, 25, $errno, $errstr, 30))
{
return TRUE;
}
else
{
return FALSE;
}
}
}

Now all thats needed is that we call the function and check the boolean output. For beginners, whenever you want to check an e-mail, just call this function:

if(checkEmail( ) == FALSE)
{
echo "E-mail entered is not valid.";
}
else
{
echo "E-mail entered is valid.";

Credit: www.spoono.com 





Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
 
< Prev   Next >
 
Se trovi uno dei nostri operatori online, contattalo prima di comprare per usufruire di uno sconto!
Servizi
Controlla PageRank
Richiedi un Preventivo
Script Gratuiti
Installazione Script
Blog Backlinks
Login Form
Prodotti Scontati
PhotoCube
PhotoCube
$44.99
$24.99
You Save: $20.00
Add to Cart
 
Copyrighted © 2006 phppod.com