微信小程序:正则表达式验证手机号码

平时我们在做微信小程序开发的时候经常会涉及到验证输入信息是否准确,我们今天就来简单介绍下,使用正则表达式来验证输入的值是否为合规的手机号码 

login.json >>

{
    "usingComponents": {
      "van-field": "@vant/weapp/field/index",
    },
    "navigationBarBackgroundColor": "#FFFFFF",
    "navigationBarTitleText": "登录"
}

 login.wxml >> 

 login.js >> 

onPhoneChange: function (event) {
    let _this = this;
    _this.setData({
        phone: event.detail
    })
},
moblieLogin: function () {
    var _this = this;
    let phone = _this.data.phone;
    if (!/^1[3456789]\d{9}$/.test(phone)) {
        wx.showToast({
            title: '请输入正确的手机号',
            icon: 'none'
        });
        return;
    }
    .......    
}

你可能感兴趣的:(三方开发,微信小程序,小程序)