1、手机
var checkPhone = (rule, value, callback) => {
if (!value) {
return callback(new Error('手机号不能为空'));
} else {
const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
console.log(reg.test(value));
if (reg.test(value)) {
callback();
} else {
return callback(new Error('请输入正确的手机号'));
}
}
};
2、邮箱
var validateEmail = (rule, value, callback) => {
if (value === '') {
callback(new Error('邮箱不能为空'));
} else {
if (value !== '') {
var reg=/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if(!reg.test(value)){
callback(new Error('请输入有效的邮箱'));
}
}
callback();
}
};
3、固定电话
1》区号+电话+分机号都在一个input填写
2》区号+电话+分机号分开填写的
<el-form-item label="公司电话">
<el-col :span="6">
<el-form-item label=" " prop="telephone.a" label-width="0px">
<el-input placeholder="区号" v-model="ruleFormCantact.telephone.a"></el-input>
</el-form-item>
</el-col>
<el-col :span="1">-</el-col>
<el-col :span="10">
<el-form-item label=" " prop="telephone.b" label-width="0px">
<el-input placeholder="电话号码" v-model="ruleFormCantact.telephone.b"></el-input>
</el-form-item>
</el-col>
<el-col :span="1">*</el-col>
<el-col :span="6">
<el-form-item label=" " prop="telephone.c" label-width="0px">
<el-input placeholder="分机" v-model="ruleFormCantact.telephone.c"></el-input>
</el-form-item>
</el-col>
</el-form-item>
***************************************
var checkA = (rule, value, callback) => {
const reg = /^(\d{4}|\d{3})$/
if (reg.test(value) || value=='') {
callback();
} else {
return callback(new Error('请输入正确的区号'));
}
};
var checkB = (rule, value, callback) => {
const reg = /^(\d{7,8})$/
if (reg.test(value)) {
callback();
} else {
return callback(new Error('请输入正确的号码'));
}
};
var checkC = (rule, value, callback) => {
const reg = /^(\d{4}|\d{3}|\d{2}|\d{1})$/
if (reg.test(value) || value=='') {
callback();
} else {
return callback(new Error('请输入正确的分机号'));
}
};
************
'telephone.a': [{ message: '', trigger: 'blur', validator: checkA}],
'telephone.b': [{ message: '', trigger: 'blur', validator: checkB}],
'telephone.c': [{ message: '', trigger: 'blur', validator: checkC}],