wxml
wxss
.all {
border-top: 1rpx solid #efefef;
border-bottom: 1rpx solid #efefef;
height: 98rpx;
font-size: 28rpx;
display: flex;
align-items: center;
}
button {
width: 480rpx;
height: 80rpx;
background-color: #7ecffd;
font-size: 30rpx;
color: #fff;
border-radius: 8px;
margin: 50rpx auto;
}
js
Page({
data: {
ajxtrue: false,
},
// 手机号验证
blurPhone: function(e) {
var phone = e.detail.value;
let that = this
if (!(/^1[34578]d{9}$/.test(phone))) {
this.setData({
ajxtrue: false
})
if (phone.length >= 11) {
wx.showToast({
title: '手机号有误',
icon: 'success',
duration: 2000
})
}
} else {
this.setData({
ajxtrue: true
})
console.log('验证成功', that.data.ajxtrue)
}
},
// 表单提交
formSubmit(e) {
let that = this
let val = e.detail.value
let ajxtrue = this.data.ajxtrue
if (ajxtrue == true) {
//表单提交进行
} else {
wx.showToast({
title: '手机号有误',
icon: 'success',
duration: 2000
})
}
},
onLoad: function(options) {
},
onReady: function() {
},
onShow: function() {
},
onHide: function() {
},
onUnload: function() {
},
onPullDownRefresh: function() {
},
onReachBottom: function() {
},
onShareAppMessage: function() {
}
})
下面看下微信小程序正则判断手机号的示例代码
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+d{8})$/;
if (this.data.Del.length == 0) {
wx.showToast({
title: '输入的手机号为空',
icon: 'success',
duration: 1500
})
return false;
} else if (this.data.Del.length < 11) {
wx.showToast({
title: '手机号长度有误!',
icon: 'success',
duration: 1500
})
return false;
} else if (!myreg.test(this.data.Del)) {
wx.showToast({
title: '手机号有误!',
icon: 'success',
duration: 1500
})
return false;
} else {
wx.showToast({
title: '填写正确',
icon: 'success',
duration: 1500
})
}
总结
以上所述是小编给大家介绍的微信小程序手机号码验证功能的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!



