PHP Regular Expression to validate email

I was originally going to use eregi() — which is not only deprecated, but removed in PHP 7.

Instead I’m using:

function isValidateEmail($EmailToCheck) {  if (strlen($EmailToCheck) == 0) return false;if (preg_match("/^[\+a-zA-Z0–9._-]+@[a-zA-Z0–9._-]+\.([a-zA-Z]{2,4})$/", $EmailToCheck))
return true;
else
return false;
}

Originally I just replaced eregi() with preg_match() but got an error. I had to change the pattern by adding “/” before and after.

Like this style of writing? 👍👍 Interested in creating a PHP web application and already know what a “variable” is and the concept of an “if” statement? Check out my book: Web Development for Intermediate Programmers — with PHP