手机号校验

<script>
// 手机号验证
const validatePhone = (rule, value, callback) => {
  if (!value) {
    callback(new Error("请输入业户联系人手机号"));
  } else {
    const reg = /^1[3|4|5|6|7|8][0-9]\d{8}$/;
    if (reg.test(value)) {
      callback();
    } else {
      return callback(new Error("业户联系人手机号不正确"));
    }
  }
};

export default {
  data() {
    return {
       rules: {
            phone: [
            {required: true,validator: validatePhone,trigger: "blur"}
          ]
       }
    }
  }
}

</script>

 

posted @ 2021-10-20 18:30  挽你手  阅读(380)  评论(0编辑  收藏  举报