文档
validator.js文档地址
规则编写示例
- element-plus 使用示例
const captchaLoginRules = {phoneNumber: [{ required: true, message: '手机号不能为空', trigger: 'blur' },{validator: (_rule: any, value: string, _callback: any): boolean => {return isMobilePhone(value, 'zh-CN')},message: '请输入正确的手机号',trigger: 'blur',},],captcha: [{ required: true, message: '验证码不能为空', trigger: 'blur' },{ min: 6, max: 6, message: '验证码长度必须为6个字符', trigger: 'blur' },],
}
- tdesign-vue-next 使用示例
const FORM_RULES = {username: [{ required: true },{validator: (value: string): boolean => {return isMobilePhone(value, 'zh-CN') || isEmail(value);},message: '请输入正确的 Email 或手机号'}],code: [{ required: true }]
};