@pit-front-end/utils
Version:
湖南创智艾泰克科技有限公司
84 lines (83 loc) • 2.36 kB
TypeScript
export declare const regularList: {
iphone: {
rule: RegExp;
msg: string;
};
password: {
rule: RegExp;
msg: string;
};
idCard: {
rule: RegExp;
msg: string;
};
email: {
rule: RegExp;
msg: string;
};
plateNumber: {
rule: RegExp;
msg: string;
};
chinese: {
rule: RegExp;
msg: string;
};
enCode: {
rule: RegExp;
msg: string;
};
enCode2: {
rule: RegExp;
msg: string;
};
userAccount: {
rule: RegExp;
msg: string;
};
userAccount1: {
rule: RegExp;
msg: string;
};
english: {
rule: RegExp;
msg: string;
};
fullName: {
rule: RegExp;
msg: string;
};
userCode: {
rule: RegExp;
msg: string;
};
allDate: {
rule: RegExp;
msg: string;
};
bigInt: {
rule: RegExp;
msg: string;
};
netUrl: {
rule: RegExp;
msg: string;
};
};
export type FormValidateType = "iphone" | "password" | "idCard" | "email" | "plateNumber" | "chinese" | "enCode" | "enCode2" | "userAccount" | "userAccount1" | "english" | "fullName" | "userCode" | "allDate" | "bigInt" | "netUrl";
export type FormValidateMsg = string;
/**
* 表单验证函数生成器
*
* 该函数用于生成表单验证函数,根据提供的验证类型和可选的错误消息,
* 创建一个验证函数,该函数可以用于验证表单输入是否符合预期的格式或条件
*
* 用法
* 1、{ validator: this.formValidate('fullName', '用户名由字母、数字、下划线以及短横线组成。'), trigger: 'blur' }
* 2、{ validator: this.formValidate('/^([w-]+|[u4e00-u9fa5]+)$/', '用户名由字母、数字、下划线以及短横线组成。'), trigger: 'blur' }
*
* @param {String} type 验证类型,对应于不同的验证规则
* @param {String} msg 可选的错误验证消息,如果未提供且验证失败时,将使用默认消息
* @returns 返回一个表单验证函数,该函数接受规则、值和回调函数作为参数
*/
export declare const formValidate: (type: FormValidateType, msg?: FormValidateMsg) => (_rule: any, value: string, callback: (arg0?: Error | undefined) => void) => void;