//获取验证码
$("#codeTips").click(function () {
let phoneNum = $("#phoneNum").val();
if (!$.trim(phoneNum)) {
alert("请填写手机号!")
return;
}
var phoneFlag = handleVali('phone');
if (phoneFlag === false) {
alert("请填写正确的手机号!")
return;
}
$.get({
url : "/users/getAuthCode",
//url: "localhost:8080/users/getAuthCode",
data : {telephone: phoneNum},
headers: {
'Content-Type': 'application/json'
},
success : function(data) {
alert("验证码发送成功!");
time();
},
error : function(data) {
if(data.responseJSON.code === 591) {
alert(data.responseJSON.message);
return;
}
alert("验证码出错!")
console.log(data)
}
})
});
//验证码倒计时
var wait = 60;
function time() {
if(wait==0) {
//可以重新点击获取验证码
$('#codeTips').on("click", function() {
let phoneNum = $("#phoneNum").val();
if (!$.trim(phoneNum)) {
alert("请填写手机号!")
return;
}
var phoneFlag = handleVali('phone');
if (phoneFlag === false) {
alert("请填写正确的手机号!")
return;
}
$.get({
url : "/api/ic-tenant-center/users/getAuthCode",
//url: "localhost:8080/users/getAuthCode",
data : {telephone: phoneNum},
headers: {
'Content-Type': 'application/json'
},
success : function(data) {
alert("验证码发送成功!");
console.log("获取验证码返回的data:",data);
},
error : function(data) {
if(data.responseJSON.code === 591) {
alert(data.responseJSON.message);
return;
}
alert("验证码出错!")
console.log(data)
}
})
});
$("#codeTips").text("| 获取验证码");
wait = 60;
}else {
$('#codeTips').off("click");
$("#codeTips").text("| " + wait+"秒后重试");
wait--;
setTimeout(function() { //倒计时方法
time();
},1000); //间隔为1s
}
}
// 校验
function handleVali(id) {
var temp = $('#' + id).children('input')[0].value;
var extral = $('#' + id).children('.setExtral');
var temCaptrue = null
if (id === 'pass') {
// 密码
temCaptrue = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
} else if (id === 'phone') {
// 手机
//temCaptrue = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
//移动
let yd = /1(3[4-9]|4[7]|5[012789]|7[28]|8[23478]|9[578])\d{8}/; //验证规则
let ydFlag = yd.test(temp);
//联通
let lt = /1(3[0-2]|4[56]|5[56]|6[6]|7[0156]|8[56]|9[6])\d{8}/; //验证规则
let ltFlag = lt.test(temp);
//电信
let dx = /1(3[3]|4[19]|5[3]|7[3479]|8[019]|9[0139])\d{8}/; //验证规则
let dxFlag = dx.test(temp);
if(ydFlag || ltFlag || dxFlag) {
extral.hide();
return true;
} else {
extral.show();
return false;
}
} else if (id === 'account') {
// 账号
temCaptrue = /^[A-Za-z0-9]*$/;
} else if (id === 'name') {
//姓名
temCaptrue = /^[a-zA-Z\u4e00-\u9fa5]+$/;
} else if (id === 'email') {
// 邮箱
temCaptrue = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
}
temCaptrue.test(temp) ? extral.hide() : extral.show();
return temCaptrue.test(temp);
}
验证码倒计时的处理
于 2021-02-25 11:26:25 首次发布