正则匹配手机号

    let phon = this.data.phon
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (phon.length == 0) {
      wx.showToast({
        title: '输入的手机号为空',
        icon: 'none',
        duration: 1500
      })
      return false;
    } else if (phon.length < 11) {
      wx.showToast({
        title: '手机号长度有误!',
        icon: 'none',
        duration: 1500
      })
      return false;
    } else if (!myreg.test(phon)) {
      wx.showToast({
        title: '手机号有误!',
        icon: 'none',
        duration: 1500
      })
      return false;
    } else {
      wx.showToast({
        title: '正确!',
        icon: 'none',
        duration: 1500
      })
    }

 

你可能感兴趣的:(微信小程序,js)