From e7ae69bead20b56eada59dd4c27f47a2ad798b80 Mon Sep 17 00:00:00 2001 From: Anyon Date: Wed, 19 Aug 2026 10:19:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20URL=20=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/plugs/admin/validate.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/static/plugs/admin/validate.js b/public/static/plugs/admin/validate.js index bbc7596f7..7b0d71835 100644 --- a/public/static/plugs/admin/validate.js +++ b/public/static/plugs/admin/validate.js @@ -18,7 +18,14 @@ define(function () { this.patterns = { qq: '^[1-9][0-9]{4,11}$', ip: '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$', - url: '^https?://([a-zA-Z0-9-]+\\.)+[-_a-zA-Z0-9-]+', + url: function (value) { + try { + let url = new URL(value); + return /^(http|https):$/.test(url.protocol) && !!url.hostname; + } catch (e) { + return false; + } + }, phone: '^1[3-9][0-9]{9}$', mobile: '^1[3-9][0-9]{9}$', email: '^([a-zA-Z0-9_\\.-])+@(([a-zA-Z0-9-])+\\.)+([a-zA-Z0-9]{2,4})+$', @@ -34,7 +41,7 @@ define(function () { pattern = pattern || el.getAttribute('pattern'); if ((value = value || $.trim($(el).val())) === '') return true; if (!(pattern = this.patterns[pattern] || pattern)) return true; - return new RegExp(pattern, 'i').test(value); + return typeof pattern === 'function' ? pattern.call(this, value, el) : new RegExp(pattern, 'i').test(value); }; this.hasProp = function (el, prop) { let attrProp = el.getAttribute(prop); @@ -111,4 +118,4 @@ define(function () { $(this).removeAttr('data-form-loaded').removeClass('layui-disabled'); }); } -}); \ No newline at end of file +});