From 43c5effcd0ecdf99ed13591a00237d3c7c4c636c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 23 Feb 2023 15:22:11 +0800 Subject: [PATCH] perf: improve the validation rules for username (#868) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 优化用户名的校验规则,目前采用 DNS 名称的规则,即:必须以字母(a-z或A-Z)开头,并包含字母数字字符(a-z,A-Z,0-9)和连字符(-)。每一段名称以字母结尾(a-z或A-Z)。名称以点(.)分隔 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3239 #### Screenshots: #### Special notes for your reviewer: 测试方式: 1. 新建用户,检查用户名输入规则是否符合预期。 #### Does this PR introduce a user-facing change? ```release-note 优化 Console 端新建用户时,用户名的校验规则。 ``` --- .../system/users/components/UserEditingModal.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/system/users/components/UserEditingModal.vue b/src/modules/system/users/components/UserEditingModal.vue index 0ad431d0..dcaf86f7 100644 --- a/src/modules/system/users/components/UserEditingModal.vue +++ b/src/modules/system/users/components/UserEditingModal.vue @@ -173,7 +173,17 @@ const handleCreateUser = async () => { label="用户名" type="text" name="name" - validation="required|alphanumeric|length:0,50" + :validation="[ + ['required'], + ['length:0,63'], + [ + 'matches', + /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/, + ], + ]" + :validation-messages="{ + matches: '请输入有效的用户名', + }" >