1、常规正则校验(pattern):
rules: {
chineseName: [
{ required: true, message: "请输入中文名称", trigger: "blur" },
{
pattern: /^[\u4E00-\u9FA5]{1,}$/,
message: "只能输入汉字",
trigger: "blur",
},
],
EnglishName: [
{ required: true, message: "请输入英文名称", trigger: "blur" },
{
pattern: /^[A-Za-z0-9_]{1,}$/,
message: "只能输入英文数字下划线",
trigger: "blur",
},
]
}
2、自定义校验规则
export default {
data() {
var effectTimeChk = (rule, value, callback) => {
if (!value) {
return callback(new Error('请输入有效时长'));
}else if (!Number(value)) {
callback(new Error('请输入数字'));
} else {
if (value < 30) {
callback(new Error('延期时长最少不得低于30天'));
} else {
callback();
}
}
};
return {
rules: {
effectiveTime:[
{ required: true, message: "请输入有效时长", trigger: "blur" },
{ validator: effectTimeChk, trigger: "blur"}
],
}
}
}
阅读(8556) | 评论(0) | 转发(0) |