Often when building applications you need to take care of security specailly when user generated content apps. Spam is our common enemy. To eradicate spam certain filters need to be implemented.
Email validation is one of them. Email validation can stop much of your spam content. Before we get started I would like to tell you that this is much simple funcion that only checks if your email is in proper format i.e email@domain.com. I won’t recommend you to use the same for your applications.
The below function will return false incase the email is not correct and returns the email address if the email address format is correct. Original idea by Regan Johnson
function verify_email($email){
if(!preg_match('/^[_A-z0-9-]+((.|+)[_A-z0-9-]+)*@[A-z0-9-]+(.[A-z0-9-]+)*(.[A-z]{2,4})$/',$email)){
return false;
} else {
return $email;
}
}
Related posts:

