Verify and e-mail address format

Last update on March 10, 2009 11:12 AM by jad05
Published by jad05

Verify and e-mail address format






There are several ways to determine if a variable contains a valid email address. These techniques do not check if email address exists, but they determine if the string contained in a variable complies with the format of an email address.

Using a filter


Using a function of the family of filters, you can check that email address is valid.

if(filter_var($email, FILTER_VALIDATE_EMAIL)){
    //e-mail is good
}

With regular expressions


It is possible to check if an email address, for example via entry form, is valid.

Here is a function that checks if a string is only a valid e-mail address.

function Verifyemailaddress($address)
{
   $Syntax='#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#';
   if(preg_match($Syntax,$address))
      return true;
   else
     return false;
}

Example of use


After getting the "address" field of a form:

$address=htmlentities($_POST['address']);
if(Verifyemailaddress($address))
  echo '<p>Your address is valid.</p>';
else
  echo '<p>Your address is not valid.</p>';

Explanations


The sharps are the regex delimiters.
The symbol ^ indicates that the string must begin with what follows, and the $ sign indicates that it must end with the above.
\ w is a class which is abbreviated to A-Za-z0-9_. either the 26 letters of the alphabet in upper or lower case, the ten digits and underscore.

What does the code do


^ [\ w. -] + @ Begins (^) by at least one character corresponding to the abbreviated class, or a dash, then followed by an @.
[\ w. -] + one or more characters corresponding to the abbreviated class or a dash (the domain name)
\. [a-zA-Z] (2.6) $ a, then two to six letters, that eventually the chain (the tld of the domain name).
Best answers for « Verify and e mail address format » in :
E-mail Address Not Verified Show [E-mail Address Not Verified] is displayed next to the username Introduction Configure your email address so that it works on MSN Messenger Introduction When you use MSN Messenger or Windows Live Messenger with an address not...
[WLM] doesn’t remember E-mail address Show [WLM] - doesn’t not remember E-mail address Issue Solution Note Issue Whenever I turn off my computer even though I checked “Remember me” on my Windows Live Messenger, it does not remember. Each time I turn my PC on I have to...
Verifying the domain of an e-mail address ShowVerifying the domain of an e-mail addresse There are two parties for an email addresse : the username and the domain name username@domain The domain part defines a set of associated machines in which it requires a server...
I did not receive the confirmation mail ShowI did not receive the confirmation mail If you signed up for kioskea but do not receive the confirmation e-mail (to confirm your registration), read this: 1. The e-mail address you provided is from AOL In this case, it is very likely...
Outlook Express – unable to open e-mail attachments ShowOutlook Express – unable to open e-mail attachments Issue Solution Issue If you are receiving e-mails with attachment files and you are unable to open or save them, this is because your antivirus is blocking access to open. It is...
Download Atomic Mail Verifier ShowAtomic Mail Verifier is simply a tool which allows to verify the validity of e-mail address list. The control is done in three levels: - control of the address syntax, - control of the existence of the address in the host server - complete...
Introduction to email ShowWhat is email? Electronic mail (also known as email or e-mail) is one of the most commonly used services on the Internet, allowing people to send messages to one or more recipients. Email was invented by Ray Tomlinson in 1972. Why use email? The...
E-mail bombing ShowE-mail Bombing E-mail bombing involves sending several thousand identical messages to an electronic mailbox in order to overflow it. E-mails are stored on a messaging server until they are picked up by the owner of the messaging account. In this...
E-mail scams - Lotteries ShowInternational lottery You receive an e-mail stating that you are the lucky winner of the first prize of a major lottery worth several (hundred) thousand euros. To pocket your winnings, all you have to do is reply to the e-mail. After earning your...