Skip to content

Commit

Permalink
Added support for internationalized domain names
Browse files Browse the repository at this point in the history
  • Loading branch information
aabboudi committed Oct 12, 2024
1 parent 66ddd9c commit 2c96382
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const default_email_options = {
allow_underscores: false,
require_display_name: false,
allow_utf8_local_part: true,
allow_idn: false,
require_tld: true,
blacklisted_chars: '',
ignore_max_length: false,
Expand Down Expand Up @@ -144,11 +145,16 @@ export default function isEmail(str, options) {
require_tld: options.require_tld,
ignore_max_length: options.ignore_max_length,
allow_underscores: options.allow_underscores,
allow_idn: options.allow_idn,
})) {
if (!options.allow_ip_domain) {
return false;
}

if (!options.allow_idn) {
return false;
}

if (!isIP(domain)) {
if (!domain.startsWith('[') || !domain.endsWith(']')) {
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const default_fqdn_options = {
allow_trailing_dot: false,
allow_numeric_tld: false,
allow_wildcard: false,
allow_idn: false,
ignore_max_length: false,
};

Expand Down Expand Up @@ -71,6 +72,11 @@ export default function isFQDN(str, options) {
return false;
}

// verify if domain is IDN
if (!options.allow_idn && !/^[a-z0-9-]+$/i.test(part)) {
return false;
}

return true;
});
}

0 comments on commit 2c96382

Please sign in to comment.