From 55ad4b2b3c53110a2fa06cd0ed8c26e1e2b504c9 Mon Sep 17 00:00:00 2001 From: unitwk Date: Fri, 5 Jan 2024 15:08:14 +0800 Subject: [PATCH] Feat: PASSWORD_REGEX --- frontend/src/tools/validator.ts | 2 ++ frontend/src/widgets/UserList.vue | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/tools/validator.ts b/frontend/src/tools/validator.ts index 732f8177..3359e799 100644 --- a/frontend/src/tools/validator.ts +++ b/frontend/src/tools/validator.ts @@ -34,3 +34,5 @@ export function reportError(error: any = {}) { console.error("Function reportError():", error); message.error(getValidatorErrorMsg(error, t("TXT_CODE_6a365d01"))); } + +export const PASSWORD_REGEX = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\x00-\x7F]{9,36}$/; diff --git a/frontend/src/widgets/UserList.vue b/frontend/src/widgets/UserList.vue index d5fbd7a7..32ecd4e2 100644 --- a/frontend/src/widgets/UserList.vue +++ b/frontend/src/widgets/UserList.vue @@ -21,6 +21,7 @@ import type { BaseUserInfo, EditUserInfo } from "@/types/user"; import _ from "lodash"; import type { AntColumnsType, AntTableCell } from "../types/ant"; import type { Key } from "ant-design-vue/es/_util/type"; +import { PASSWORD_REGEX } from "../tools/validator"; defineProps<{ card: LayoutCard; @@ -236,8 +237,7 @@ const addUserRules: Record = { min: 9, max: 36, validator: async (_rule: Rule, value: string) => { - if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[0-9A-Za-z]{9,}$/.test(value)) - throw new Error(t("TXT_CODE_6032f5a3")); + if (!PASSWORD_REGEX.test(value)) throw new Error(t("TXT_CODE_6032f5a3")); }, trigger: "blur" } @@ -253,8 +253,7 @@ const editUserRules: Record = { min: 9, max: 36, validator: async (_rule: Rule, value: string) => { - if (value && !/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[0-9A-Za-z]{9,}$/.test(value)) - throw new Error(t("TXT_CODE_6032f5a3")); + if (value && !PASSWORD_REGEX.test(value)) throw new Error(t("TXT_CODE_6032f5a3")); }, trigger: "blur" }