界面設(shè)計(jì)
頁面引用了youzan組件進(jìn)行設(shè)計(jì),包括icon,button,tag,toast以及布局
github地址:https://github.com/youzan/zanui-weapp
實(shí)現(xiàn)的功能
1.對用戶輸入的手機(jī)號碼進(jìn)行驗(yàn)證,利用正則表達(dá)式:
var reg = /^1[3|4|5|7|8][0-9]{9}$/
驗(yàn)證函數(shù):
用戶輸入錯誤的手機(jī)號碼時將會調(diào)用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: '請輸入正確的手機(jī)號', selector: '#zan-toast-test' }); } },
2.驗(yàn)證圖片驗(yàn)證碼(暫時為靜態(tài)數(shù)據(jù)嘻嘻)
用戶輸入正確的手機(jī)號碼后,會顯示要求用戶輸入圖片驗(yàn)證碼進(jìn)行驗(yàn)證,驗(yàn)證成功后將會下發(fā)短信驗(yàn)證碼給用戶的手機(jī)
// 圖片驗(yàn)證碼驗(yàn)證 ValatedCode: function(){ var code = this.data.valatedCode.toLowerCase() if (code == '3n3d') { this.setData({ isValated: false }) Toast({ message: '驗(yàn)證碼已發(fā)送', selector: '#zan-toast-test' }); this.getCode() this.setData({ disabled: true }) } else { this.setData({ isValated: false }) Toast({ message: '圖片驗(yàn)證碼輸入錯誤', selector: '#zan-toast-test' }); } },
3. 實(shí)現(xiàn)發(fā)送驗(yàn)證碼60s倒計(jì)時
var interval = null //倒計(jì)時函數(shù) data: { fun_id:2, time: '獲取驗(yàn)證碼', //倒計(jì)時 currentTime:61, userPhone: '', isValated: false, valatedCode: '' }, getCode: function (options){ var that = this; var currentTime = that.data.currentTime interval = setInterval(function () { currentTime--; that.setData({ time: '已發(fā)送('+currentTime+'s)' }) if (currentTime <= 0) { clearInterval(interval) that.setData({ time: '重新發(fā)送', currentTime:61, disabled: false }) } }, 1000) },
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com