Feat: PASSWORD_REGEX

This commit is contained in:
unitwk 2024-01-05 15:08:14 +08:00
parent 766064750f
commit 55ad4b2b3c
2 changed files with 5 additions and 4 deletions

View File

@ -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}$/;

View File

@ -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<string, Rule[]> = {
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<string, Rule[]> = {
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"
}