//1、input标签设置只能输入数字

//input标签上加上 oninput="value=value.replace(/[^0-9.]/g,'')",如
  <el-input v-model="a" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>

//2、在只能输入数字的基础上,设置手机号验证

<template>
  <el-input v-model="a" onblur="vaildPhone" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
</template>
<script>
export default {
  data() {
    return {
      a: 1,
    };
  },
  methods: {
    testPhone(str) {
      const reg = /^1[3|4|5|7|8|6|9][0-9]\d{8}$/;
      return reg.test(str);
    },
    vaildPhone() {
      if (!this.testPhone(this.a)) {
        alert("手机号错误");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
</style>

  

 

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2021-11-20
  • 2022-12-23
  • 2022-01-24
  • 2022-01-19
  • 2021-06-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-12-18
相关资源
相似解决方案