It might be a bit redundant, and I'm not experienced enough to wrap it all into one function. But, I'm aiming for unicode email adresses and a quick loose but secure validation. How can I improve this?
note: I'm using PDO, so I'm mainly focusing on preventing HTML injection. Is this an issue ether way if I'm outputting user input in htmlspecialchars?
$email = "<strong>Bàt mâ'n</strong>@çupærman.dc";
function isValid($email) {
return !preg_match('/[^ ]+@[^ ]+\.[^ ]{2,7}/', $email);
}
$encoded_email = htmlspecialchars($email, ENT_COMPAT, 'UTF-8');
if (isValid($email)) {
echo $encoded_email. " is not valid!";
} else {
if ($encoded_email===$email) {
echo $encoded_email. " is valid!";
} else {
echo $encoded_email. " is not valid!";
}
}