Universal Acceptance Update (3/3)

This commit is contained in:
Pinga 2024-11-01 13:58:24 +02:00
parent f60b59b00b
commit be965db4cc
5 changed files with 78 additions and 38 deletions

View file

@ -576,4 +576,14 @@ function validateUniversalEmail($email) {
// Validate using regex
return preg_match($emailPattern, $emailToValidate);
}
function toPunycode($value) {
// Convert to Punycode if it contains non-ASCII characters
return preg_match('/[^\x00-\x7F]/', $value) ? idn_to_ascii($value, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : $value;
}
function toUnicode($value) {
// Convert from Punycode to UTF-8 if it's a valid IDN format
return (strpos($value, 'xn--') === 0) ? idn_to_utf8($value, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : $value;
}