小程序实现手机短信验证功能

小程序实现手机短信验证功能

废话不多说,直接把项目写的手机短信验证功能发出来

.wxml

<form bindsubmit="phone">
<input type='number' name="loginMobile" bindinput='changeSearch' placeholder='请输入新的手机号' maxlength='11'></input>
     <button  class='verfiCode' bindtap="codes" disabled="{{disabled}}">{{codename}}</button>
     <button form-type="submit" class='submit'>提交</button>
</form>

.js

var api = require('../../utils/api.js');
var http = require('../../utils/httpUtil.js');
Page({
  data: {
    codename: '获取验证码',
  },
  //获取短信
 codes:function(e){
    let mobile = this.data.inputValue;
    let myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    console.log('手机号:',this.data.inputValue)
    if (myreg.test(mobile)) {
      let vinse = {
        mobile: this.data.inputValue
      }
       let that = this
      let token = wx.getStorageSync('token');
      http.request(api.verification, vinse, 'get', '查询', token, null).then(function (res) {//请求服务器
        that.setData({
          codesin: res.data
        })
        if (res.code == '200') {
          //获取验证码成功想要等待60秒
          let num = 60
          let timer = setInterval(function () {
            num--;
            if (num <= 0) {
              clearInterval(timer);
              that.setData({
                codename: '重新发送',
                disabled: false
              })
            } else {
              that.setData({
                codename: num + 's',
                disabled: true
              })
            }
          }, 1000)
          }
      })
    }else{
      wx.showToast({
        title: '手机号有误',
        icon: 'none',
      })
    }
  },
  //获取手机号码值
  changeSearch: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },

只发了小程序写的手机短信功能,有什么问题欢迎评论留言,我会及时回复你的。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值