0
Thanks

A few words of thanks would be greatly appreciated.

PHP - Checking the format of an email address





Here below you chould find sp techniques to determine if a variable contains a valid email address.

Using a filter

Using these type of fuction, you can check if email address is valid.
filter_var ()
Example:

if(filter_var($email, FILTER_VALIDATE_EMAIL)){
//Email is good
}

Using regular expressions

With regular expressions, it is possible to check if an email address, obtained via a form, is valid.

Here is a function that checks if a string is only an e-mail address valide.function VerifierAdresseMail ($ address)

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

Implementation

After getting the address a form:

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

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

Original article published by . Translated by jak58. Latest update on by Olivia Long.

This document, titled "PHP - Checking the format of an email address," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments