本文實(shí)例講述了微信小程序?qū)崿F(xiàn)基于三元運(yùn)算驗(yàn)證手機(jī)號(hào)/姓名功能。分享給大家供大家參考,具體如下:
wxml部分:
<view class="fl_form" style="position:relative;padding-top:20rpx;"> <text><text style="color:red;padding-right:10rpx">*</text>您的姓名</text> <input type="text" placeholder='請(qǐng)輸入您的姓名' value="{{trueName}}" bindblur='userNameInput'></input> <text class="{{isName=='1'?'show':'hidden'}}">姓名不能為空</text> </view> <view class="fl_form"> <text><text style="color:red;padding-right:10rpx">*</text>所屬部門(mén)</text> <input type="text" placeholder='請(qǐng)輸入所屬部門(mén)' value="{{deparment}}" bindblur='userBranchInput'></input> <text class="{{isDeparment=='1'?'show':'hidden'}}">部門(mén)不能為空</text> </view> <view class="fl_form" style="padding-bottom:20rpx;"> <text><text style="color:red;padding-right:10rpx">*</text>聯(lián)系電話</text> <input type="number" placeholder='請(qǐng)輸入聯(lián)系電話' maxlength='11' value="{{phone}}" bindblur='userTellInput'></input> <text class="{{isPhone=='1'?'show':'hidden'}}" style="width:35%">請(qǐng)輸入有效的手機(jī)號(hào)</text> </view>
js部分:
data: { trueName: "", deparment: "", phone: "", isName: "", isDeparment: "", isPhone: "", }, //事件處理函數(shù) userNameInput: function (e) { //用戶姓名 if (e.detail.value) { console.log(e.detail.value) this.setData({ isName: '', trueName: e.detail.value }) } else { this.setData({ isName: '1' }) } }, userBranchInput: function (e) { //所屬部門(mén) if (e.detail.value) { this.setData({ isDeparment: '', deparment: e.detail.value }) } else { this.setData({ isDeparment: '1' }) } }, userTellInput: function (e) { //聯(lián)系電話 if (/^1[3|4|5|6|7|8|9]\d{9}$/.test(e.detail.value)) { this.setData({ phone: e.detail.value, isPhone: "" }) } else { this.setData({ isPhone: "1" }) } }
本機(jī)測(cè)試運(yùn)行結(jié)果:
希望本文所述對(duì)大家微信小程序開(kāi)發(fā)有所幫助。