From 0478a2f957cf8c5ce4240b12c840bc911229891a Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Mon, 20 Nov 2023 08:25:01 +0700 Subject: [PATCH] use another domain regex pattern to fix domain validation --- lib/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index dd91e21..42f9ac5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -12,7 +12,9 @@ if (!globalThis.fetch) { * @param {string} value The value to be checked. */ export const isValidDomain = (value) => - /^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/.test(value); + /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/.test( + value + ); /** * Extracts all subdomains from a domain including itself.