直接上代码:
data() {
//支持座机、400热线、手机号校验
var validateHotLine = (rule, value, callback) => {
let reg = /(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^((\(\d{3}\))|(\d{3}\-))?(1[3578]\d{9})$)|(^(400)-(\d{3})-(\d{4})(.)(\d{1,4})$)|(^(400)-(\d{3})-(\d{4}$))/;
if (value == '') {
callback(new Error("热线电话不能为空"));
} else if (!reg.test(value)) {
callback(new Error("热线电话填写有误"));
}
callback();
};
//手机号校验非严格校验,仅1开头第二位为2-9即可的11位手机号
var validateMobile = (rule, value, callback) => {
if (!value || value &