效果图:
WXML:
<view class="flex-item solid1rpx margin-top15rpx">
<label class='font-size27rpx ' style='float:left'>电话</label>
<input class="input-margin-left" type="number" name="ContactNumber" placeholder="请填写联系电话" value='{{ContactNumber}}' maxlength='11' style='width:500rpx;font-size: 27rpx;' bindinput="inputPhoneNum" />
</view>
JS:
// 验证手机号
inputPhoneNum: function (e) {
let phoneNumber = e.detail.value
if (phoneNumber.length === 11) {
let checkedNum = this.checkPhoneNum(phoneNumber)
}
},
checkPhoneNum: function (phoneNumber) {
let str = /^1[34578]\d{9}$/
if (str.test(phoneNumber)) {
return true
} else {
wx.showToast({
title: '手机号不正确',
icon: 'none'
})
return false
}
},