微信小程序手機(jī)號(hào)碼驗(yàn)證功能的實(shí)例代碼
wxml
<form bindsubmit='formSubmit'> <view class='all'> <text>手機(jī)號(hào):</text> <input name="phone" placeholder='請(qǐng)輸入手機(jī)號(hào)' type='number' style='color:#333' placeholder-style="color:#666" maxlength="11" bindinput='blurPhone'></input> </view> <button formType="submit">保存</button> </form>
wxss
.all { border-top: 1rpx solid #efefef; border-bottom: 1rpx solid #efefef; height: 98rpx; font-size: 28rpx; display: flex; align-items: center; } button { width: 480rpx; height: 80rpx; background-color: #7ecffd; font-size: 30rpx; color: #fff; border-radius: 8px; margin: 50rpx auto; }
js
Page({ /** * 頁面的初始數(shù)據(jù) */ data: { ajxtrue: false, }, // 手機(jī)號(hào)驗(yàn)證 blurPhone: function(e) { var phone = e.detail.value; let that = this if (!(/^1[34578]\d{9}$/.test(phone))) { this.setData({ ajxtrue: false }) if (phone.length >= 11) { wx.showToast({ title: '手機(jī)號(hào)有誤', icon: 'success', duration: 2000 }) } } else { this.setData({ ajxtrue: true }) console.log('驗(yàn)證成功', that.data.ajxtrue) } }, // 表單提交 formSubmit(e) { let that = this let val = e.detail.value let ajxtrue = this.data.ajxtrue if (ajxtrue == true) { //表單提交進(jìn)行 } else { wx.showToast({ title: '手機(jī)號(hào)有誤', icon: 'success', duration: 2000 }) } }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function(options) { }, /** * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 */ onReady: function() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面顯示 */ onShow: function() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面隱藏 */ onHide: function() { }, /** * 生命周期函數(shù)--監(jiān)聽頁面卸載 */ onUnload: function() { }, /** * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作 */ onPullDownRefresh: function() { }, /** * 頁面上拉觸底事件的處理函數(shù) */ onReachBottom: function() { }, /** * 用戶點(diǎn)擊右上角分享 */ onShareAppMessage: function() { } })
下面看下微信小程序正則判斷手機(jī)號(hào)的示例代碼
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/; if (this.data.Del.length == 0) { wx.showToast({ title: '輸入的手機(jī)號(hào)為空', icon: 'success', duration: 1500 }) return false; } else if (this.data.Del.length < 11) { wx.showToast({ title: '手機(jī)號(hào)長度有誤!', icon: 'success', duration: 1500 }) return false; } else if (!myreg.test(this.data.Del)) { wx.showToast({ title: '手機(jī)號(hào)有誤!', icon: 'success', duration: 1500 }) return false; } else { wx.showToast({ title: '填寫正確', icon: 'success', duration: 1500 }) }
總結(jié)
以上所述是小編給大家介紹的微信小程序手機(jī)號(hào)碼驗(yàn)證功能的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 微信小程序?qū)崿F(xiàn)手機(jī)驗(yàn)證碼登錄
- 微信小程序?qū)崿F(xiàn)手機(jī)獲取驗(yàn)證碼倒計(jì)時(shí)60s
- 微信小程序獲取手機(jī)驗(yàn)證碼的方法
- 微信小程序手機(jī)號(hào)驗(yàn)證碼登錄的項(xiàng)目實(shí)現(xiàn)
- 微信小程序綁定手機(jī)號(hào)獲取驗(yàn)證碼功能
- 微信小程序?qū)崿F(xiàn)基于三元運(yùn)算驗(yàn)證手機(jī)號(hào)/姓名功能示例
- 微信小程序如何獲取手機(jī)驗(yàn)證碼
- 微信小程序 功能函數(shù)小結(jié)(手機(jī)號(hào)驗(yàn)證*、密碼驗(yàn)證*、獲取驗(yàn)證碼*)
- 微信小程序?qū)崿F(xiàn)手機(jī)號(hào)碼驗(yàn)證
相關(guān)文章
js實(shí)現(xiàn)文字超出部分用省略號(hào)代替實(shí)例代碼
關(guān)于超出一定字?jǐn)?shù)用省略號(hào)顯示的問題,這種要求在我們?nèi)粘i_發(fā)的時(shí)候經(jīng)常見到,我們之前基本都是用CSS來完成的,今天給大家分享個(gè)Javascript實(shí)現(xiàn)這個(gè)功能的示例代碼,有需要的可以參考借鑒。2016-09-09js 獲取后臺(tái)的字段 改變 checkbox的被選中的狀態(tài) 代碼
js 獲取后臺(tái)的字段 改變 checkbox的被選中的狀態(tài) 代碼,需要的朋友可以參考一下2013-06-06實(shí)現(xiàn)JavaScript中數(shù)據(jù)響應(yīng)的方法總結(jié)
JavaScript 數(shù)據(jù)響應(yīng)是一種重要的前端開發(fā)概念,是指在應(yīng)用程序中的數(shù)據(jù)發(fā)生變化時(shí),能夠自動(dòng)更新與這些數(shù)據(jù)相關(guān)的用戶界面(UI)部分的能力,本文我們來總結(jié)一下目前可以簡單實(shí)現(xiàn) JavaScript 中的數(shù)據(jù)響應(yīng)的方法,需要的朋友可以參考下2023-09-09JavaScript動(dòng)態(tài)添加事件之事件委托
動(dòng)態(tài)添加事件實(shí)質(zhì)就是指js中的事件委托。本文給大家介紹JavaScript動(dòng)態(tài)添加事件之事件委托的相關(guān)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-07-07escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法
這篇文章主要介紹了escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法,需要的朋友可以參考下2014-07-07在javascript中,如果刪除二維數(shù)組中重復(fù)的元素
在javascript中,如果刪除二維數(shù)組中重復(fù)的元素...2007-05-05