IP地址校验
rules: {
'gbe.eno1.ipaddr': [
{ required: true, message: '请输入IP地址', trigger: 'blur' },
{
validator: (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入IP地址'))
} else {
const reg =
/^((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))$/
if (!reg.test(value)) {
callback(new Error('请输入正确的IP地址'))
} else {
callback()
}
}
},
},
],
}
两次密码一样确认校验
registFormRules: {
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
{
min: 3,
max: 12,
message: '长度在 3 到 12 个字符',
trigger: 'blur',
},
{ validator: validQC, trigger: 'blur' },
],
password1: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{
min: 6,
max: 15,
message: '长度在 6 到 12 个字符',
trigger: 'blur',
},
],
password2: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{
min: 6,
max: 15,
message: '长度在 6 到 12 个字符',
trigger: 'blur',
},
{
validator: (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'))
} else if (value !== this.addForm.password1) {
callback(new Error('两次输入密码不一致!'))
} else {
callback()
}
},
trigger: 'blur',
},
],
},
类型校验
{ type: 'number', min: 0, max: 100, message: '最小值:0; 最大值:255;' },