const validName = (rule, value, callback) => {
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
callback(new Error('请输入数字、字母、下划线、-!'));
} else {
callback();
}
};
const validCnName = (rule, value, callback) => {
if (!/^[\u4E00-\u9FA5a-zA-Z0-9_-]+$/.test(value)) {
callback(new Error('请输入数字、字母、下划线、-、中文!'));
} else {
callback();
}
};
const filedStandardFormRules = {
type: [
{ required: true, message: '请选择分类', trigger: 'change'}
],
code: [
{ required: true, message: '请输入名称', trigger: 'blur' },
{
validator: validName,
message: '请输入数字、字母、下划线、-',
trigger: 'blur'
}
],
name: [
{ required: true, message: '请输入中文名称', trigger: 'blur' },
{
validator: validCnName,
message: '请输入数字、字母、下划线、-、中文',
trigger: 'blur'
}
]
};
console