小程序验证码
wxml
js
Page({
data: {
phone: '', //手机号
code: '', //验证码
iscode: null, //存放接口获取到的code
codename: '发送'
},//获取input的值
getPhoneValue: function(e) {
this.setData({
phone: e.detail.value
})
},
getCodeValue: function(e) {
this.setData({
code: e.detail.value
})
},
getCode: function() {
var a = this.data.phone;
var _this = this;
var myreg = /^1[3456789]\d{9}$/;
if (this.data.phone == "") {
wx.showToast({
title: '手机号不能为空',
icon: 'none',
duration: 1000
})
return false;
} else if (!myreg.test(this.data.phone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
return false;
} else {
wx.request({
data: {},
url: "接口",
success(res) {
console.log(res.data.data)
_this.setData({
iscode: res.data.data
})
var num = 61;
var timer = setInterval(function() {
num--;
if (num <= 0) {
clearInterval(timer);
_this.setData({
codename: '重新发送',
disabled: false
})} else {
_this.setData({
codename: num + "s"
})
}
}, 1000)
}
})
}
},//获取验证码
getVerificationCode() {
this.getCode();
var _this = this
_this.setData({
disabled: true
})
},
//提交表单信息
save: function() {
var myreg = /^1[3456789]\d{9}$/;
if (this.data.phone == "") {
wx.showToast({
title: '手机号不能为空',
icon: 'none',
duration: 1000
})
return false;
} else if (!myreg.test(this.data.phone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 1000
})
return false;
}
if (this.data.code == "") {
wx.showToast({
title: '验证码不能为空',
icon: 'none',
duration: 1000
})
return false;
} else if (this.data.code != this.data.iscode) {
wx.showToast({
title: '验证码错误',
icon: 'none',
duration: 1000
})
return false;
} else {
wx.setStorageSync('phone', this.data.phone);
wx.redirectTo({
url: '',
})
}
},
推荐阅读
- 一个小故事,我的思考。
- 家乡的那条小河
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- 昨夜小楼听风
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 基于微信小程序带后端ssm接口小区物业管理平台设计
- 2019.4.18感恩日记
- 那件我们忽略的小事叫感恩
- 你有婚内虐待行为吗()