Noticed while having a look at #27474
We make use of FILTER_VALIDATE_URL and FILTER_VALIDATE_EMAIL but both don't support internationalized domains (IDNs), which need to be converted to punycode before being validated.
The function should be available in OCP because a few core apps make use of these filters. It should look like the following:
/**
* @return string | boolean
*/
function validateEmail(string $email) {
$pos = strrpos($email, '@');
if ($pos === false) {
return false;
}
$domain = validateDomain(substr($email, $pos + 1));
if (!$domain) {
return false;
}
$ascii_email = substr($email, 0, $pos) . '@' . $domain;
return filter_var($ascii_email, FILTER_VALIDATE_EMAIL);
}
/**
* @return string|boolean
*/
function validateDomain(string $domain) {
return filter_var(idn_to_ascii($domain), FILTER_VALIDATE_URL);
}
Noticed while having a look at #27474
We make use of
FILTER_VALIDATE_URLandFILTER_VALIDATE_EMAILbut both don't support internationalized domains (IDNs), which need to be converted to punycode before being validated.The function should be available in
OCPbecause a few core apps make use of these filters. It should look like the following: