平时我们在做微信小程序开发的时候经常会涉及到验证输入信息是否准确,我们今天就来简单介绍下,使用正则表达式来验证输入的值是否为合规的手机号码
login.json >>
{
"usingComponents": {
"van-field": "@vant/weapp/field/index",
},
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTitleText": "登录"
}
login.wxml >>
<van-field type="number" clearable maxlength="11" label="手机号码" placeholder="请输入手机号码" border="{{ false }}" bind:change="onPhoneChange" />
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;
}
.......
}