Vue - Ant Design 添加正则验证
<a-form-item
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label="地块名称"
>
<a-input placeholder="请输入地块名称" v-decorator="['areaName', validatorRules.areaName]" />
</a-form-item>
validatorRules:{
areaName:{
rules:[
{required: true,message:"地块名称不能为空"},
{validator: this.validateAreaName}
]
},
},
validateAreaName(rule, value, callback){
if (!value){
callback()
} else {
let reg = /^\S+$/
if (!reg.test(value)){
callback("地块名称不合法")
}
// 该处缺少导致验证完不能继续执行
callback()
}
},