vue前端手机号码校验
<a-form-model-item
layout="inline"
label="上报电话"
:colon="false"
prop="reportMobile"
>
<a-input
placeholder="请输入电话号码"
v-model="addObj.data.reportMobile"
:maxLength="11"
style="width: 100%"
allowClear
>
</a-input>
</a-form-model-item>
let checkPhone = (rule, value, callback) => {
if (value) {
let isPhone = /^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
let reg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
// if () {
// cbfn("");
// }
if (!reg.test(value) && !isPhone.test(value) && value) {
callback(new Error("请输入正确的手机号"));
} else {
callback();
}
} else {
callback();
}
};
reportMobile: [
{ validator: checkPhone, trigger: "change" },
{ required: true, message: "请输入", trigger: "change" },
],