╰┈➤ Create a function that accepts a string, checks if it's a valid email address and returns either
true
or
false
function validateEmail($email) {
if ($email == "") {
return false; "\n";
}
$reversed = strrev($email);
$position = strpos($email, "@");
if (substr_count($email, "@") == 1 && $position > 0 && ord($email[$position + 1]) > 96
&& ord($email[$position+1])<123 && substr_count($email, ".") > 0
&& strpos($reversed, ".") < strpos($reversed, "@") - 1 && $reversed[0] != ".") {
return true; "\n";
}
return false; "\n";
}
echo(validateEmail('@edabit.com')); //false
echo(validateEmail('bill.gates@microsoft.com'));//true