Email validation snippet in PHP

Submitted by:Jhon Brain

Date added:14 August, 2012

Category:PHP

PHP code to validate email

Tags: email validation

Code Snippet:

$email = $_POST['email'];
if(preg_match("~([a-zA-Z0-9!#$%&'*+-/=?^_`{|}~])@([a-zA-Z0-9-]).([a-zA-Z0-9]{2,4})~",$email)) {
echo 'This is a valid email.';
} else{
echo 'This is an invalid email.';
}
 
 

Comments