Skip to content

Commit

Permalink
fix: option allow_numeric_tld option in isFQDN
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOsvaap committed Mar 13, 2022
1 parent c1b21a9 commit c605fe6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function isFQDN(str, options) {
return false;
}

if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
}

Expand Down
13 changes: 12 additions & 1 deletion test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,18 @@ describe('Validators', () => {
],
});
});

it('should validate FQDN with required allow_trailing_dot, allow_underscores and allow_numeric_tld options', () => {
test({
validator: 'isFQDN',
args: [
{ allow_trailing_dot: true, allow_underscores: true, allow_numeric_tld: true },
],
valid: [
'abc.efg.g1h.',
'as1s.sad3s.ssa2d.',
],
});
});
it('should validate alpha strings', () => {
test({
validator: 'isAlpha',
Expand Down

0 comments on commit c605fe6

Please sign in to comment.