微信小程序注册验证(姓名和手机号),直接上代码:
wxml:
<view class='information'>填写信息</view> <view class='top_line'></view> <view class='name'>姓名</view> <input class='btn' type="text" placeholder='请输入预约人姓名' maxlength='12'value="" bindinput ="userNameInput" ></input> <view class='line'></view> <view class='call'>手机号</view> <input class='btn' type="text" placeholder='请输入手机号' maxlength='11'value="" bindinput ="mobileInput" ></input> <view class='line'></view> <button class='confirm' type="submit" bindtap='btnclick' >确认预约</button>
js:
data: { userName:'', mobile:'' }, userNameInput: function (e) { this.setData({ userName: e.detail.value }) }, mobileInput: function (e) { this.setData({ mobile: e.detail.value }) }, btnclick:function(){ var userName = this.data.userName; var mobile = this.data.mobile; var phonetel = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/; var name = /^[u4E00-u9FA5]+$/; if (userName == '') { wx.showToast({ title: '请输入用户名', icon: 'succes', duration: 1000, mask: true }) return false } else if (mobile == '') { wx.showToast({ title: '手机号不能为空', }) return false } else if (mobile.length != 11) { wx.showToast({ title: '手机号长度有误!', icon: 'success', duration: 1500 }) return false; } var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/; if (!myreg.test(mobile)) { wx.showToast({ title: '手机号有误!', icon: 'success', duration: 1500 }) return false; } return true; },
网友评论文明上网理性发言 已有2人参与
发表评论:
评论列表