界面設計
頁面引用了youzan組件進行設計,包括icon,button,tag,toast以及布局
github地址:https://github.com/youzan/zanui-weapp
實現的功能
1.對用戶輸入的手機號碼進行驗證,利用正則表達式:
var reg = /^1[3|4|5|7|8][0-9]{9}$/
驗證函數:
用戶輸入錯誤的手機號碼時將會調用toast組件提示用戶
getVerificationCode: function(e){ var reg = /^1[3|4|5|7|8][0-9]{9}$/ var phone = this.data.userPhone var flag = reg.test(phone) if(flag){ var that = this var code this.setData({ isValated: true }) } else{ Toast({ message: '請輸入正確的手機號', selector: '#zan-toast-test' }); } },
2.驗證圖片驗證碼(暫時為靜態數據嘻嘻)
用戶輸入正確的手機號碼后,會顯示要求用戶輸入圖片驗證碼進行驗證,驗證成功后將會下發短信驗證碼給用戶的手機
// 圖片驗證碼驗證 ValatedCode: function(){ var code = this.data.valatedCode.toLowerCase() if (code == '3n3d') { this.setData({ isValated: false }) Toast({ message: '驗證碼已發送', selector: '#zan-toast-test' }); this.getCode() this.setData({ disabled: true }) } else { this.setData({ isValated: false }) Toast({ message: '圖片驗證碼輸入錯誤', selector: '#zan-toast-test' }); } },
3. 實現發送驗證碼60s倒計時
var interval = null //倒計時函數 data: { fun_id:2, time: '獲取驗證碼', //倒計時 currentTime:61, userPhone: '', isValated: false, valatedCode: '' }, getCode: function (options){ var that = this; var currentTime = that.data.currentTime interval = setInterval(function () { currentTime--; that.setData({ time: '已發送('+currentTime+'s)' }) if (currentTime <= 0) { clearInterval(interval) that.setData({ time: '重新發送', currentTime:61, disabled: false }) } }, 1000) },
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答