标签:string title exp min boolean object 提示 max tle
使用async-validator库,校验数据是否合法,并且根据校验规则给出提示信息。
必填不能为空
{"required": true, "message": "请输入内容","trigger": "blur"},
下拉框、单选框、复选框等用trigger: ‘change‘
输入框、文本域判断字数
{"min": 3, "max": 5, "message": "长度在 3 到 5 个字符"}
数组长度限制
{type: ‘array‘, max: 2, message: ‘最多只能选择2个‘}
验证type
{ type: ‘email‘, message: ‘您的邮箱输入错误‘}
type:
string
(默认),number
, boolean
,method
, regexp
,integer
,float
,array
,object
,enum
,date
,url
, hex
, email
.
正则
{pattern: /^1[34578]\d{9}$/, message: ‘您的手机号码输入错误‘}
复合输入框 selectInput
"rules": [
{
"type": "array", "required": true, "message": "请选择",
"fields": {
"0": {"required": true,"message": "请选择"},
"1": {"required": false,"message": "请输入内容"}
}
}
]
例:
标签:string title exp min boolean object 提示 max tle
原文地址:https://www.cnblogs.com/conglvse/p/9847741.html