// 验证邮箱格式
function checkEmail(email) {
var pattern = /^[A-Za-zd]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;
return pattern.test(email);
}
// 验证密码格式-密码由6-18位字母、数字、字符(包含!@#$%^*_)组成
function checkPassword(password) {
var pattern = /^[\\!@#$%^&*_\d\w]{6,18}$/;
return pattern.test(password);
}
// 验证步骤
$('#btn_part1').click(function() { // 第一步
var email = $.trim($('#email').val()); // 邮箱
var code = $.trim($('#email_code').val());// 邮箱验证码
var code_math = $.trim($('#code_math').val()); // 算术验证码
if (!email) {
layer.tips('<p style="font-size:18px;">请输入邮箱地址!</p>', '#email',{ tips: [3, '#fd5004']});
return false;
}
if (!checkEmail(email)) {
layer.tips('<p style="font-size:18px;">邮箱格式不正确!</p>', '#email',{ tips: [3, '#fd5004']});
return false;
}
if (!code_math) {
layer.tips('<p style="font-size:18px;">请输入验证码!</p>', '#code_math',{ tips: [3, '#fd5004']});
return false;
}
if (!code) {
layer.tips('<p style="font-size:18px;">请输入验证码!</p>', '#email_code',{ tips: [3, '#fd5004']});
return false;
}
if (code && code.length != 6) {
layer.tips('<p style="font-size:18px;">请输入6位数的验证码!</p>', '#email_code',{ tips: [3, '#fd5004']});
return false;
}
$.post(
"{{ url('checkcallbackcodezc') }}",
{
email: email,
code: code,
code_math: code_math,
_token: "{{ csrf_token() }}"
},
function(data,textStatus){
if(data.code==3){
return layer.tips('<p style="font-size:18px;">答案输入有误!</p>', '#code_math',{ tips: [3, '#fd5004']});
}
if(data.code==0){
return layer.tips('<p style="font-size:18px;">'+data.msg+'</p>', '#btn_part1',{ tips: [3, '#fd5004']});
}
if(data.code==1){//跳转到下一步
$('#parent_2_email').val(email);
$('#email_two').html(email);
$('#btn_part1').closest('.formSub').hide().next().show().next().hide();
$('#btn_part1').closest('.cbPassword').find('.Password li').eq(1).addClass('active').siblings().removeClass('active');
}
},
"json"
);
});
$('#btn_part2').click(function(){ // 第二步
var email = $('#parent_2_email').val();
var password = $.trim($('#password').val());
var re_password = $.trim($('#confirm_password').val());
if (!password) {
layer.tips('<p style="font-size:18px;">请输入密码!</p>', '#password',{ tips: [3, '#fd5004']});
return false;
}
if (!checkPassword(password)) {
layer.tips('<p style="font-size:18px;">密码只能由6至20字母数字和下划线“_”组成!</p>', '#password',{ tips: [3, '#fd5004']});
return false;
}
if (!re_password) {
return layer.tips('<p style="font-size:18px;">请确认新密码</p>', '#confirm_password',{ tips: [3, '#fd5004']});
}
if (password != re_password) {
return layer.tips('<p style="font-size:18px;">密码不一致</p>', '#confirm_password',{ tips: [3, '#fd5004']});
}
$.post(
"{{ url('changepasswordzc') }}",
{
email: email,
password: password,
_token: "{{ csrf_token() }}"
},
function(data,textStatus) {
if (data.code == 0) {
layer.tips('<p style="font-size:18px;">'+data.msg+'</p>', '#btn_part2',{ tips: [3, '#fd5004']});
}
if (data.code == 1) {
$('#btn_part2').closest('.formSub').hide().next().show().next().hide();
$('#btn_part2').closest('.cbPassword').find('.Password li').eq(2).addClass('active').siblings().removeClass('active')
}
},
"json"
);
})
获取验证码
/*******************点击获取验证码***********************/
var InterValObj; //timer变量,控制时间
var count = 59; //间隔函数,1秒执行
var curCount;//当前剩余秒数
//点击获取验证码
$("#send").click(function() {
var code_math = $("#code_math").val();
var email = $("#email").val();
if (!email) {
layer.tips('<p style="font-size:18px;">请输入邮箱地址!</p>', '#email',{ tips: [3, '#fd5004']});
return false;
}
if (!checkEmail(email)) {
layer.tips('<p style="font-size:18px;">邮箱格式不正确!</p>', '#email',{ tips: [3, '#fd5004']});
return false;
}
if (!code_math) {
layer.tips('<p style="font-size:18px;">请输入验证码!</p>', '#code_math',{ tips: [3, '#fd5004']});
return false;
}
$.post(
"{{ url('sendemailcode') }}",
{
email: email,
code_math: code_math,
_token:"{{csrf_token()}}",
isshare: 1
},
function (data,status) {
if(data.code==3){
layer.tips('<p style="font-size:18px;">答案输入有误!</p>', '#code_math',{ tips: [3, '#fd5004']});
return false;
}
if (data.code==0) {
layer.tips('<p style="font-size:18px;">'+data.msg+'</p>', '#email',{ tips: [3, '#fd5004']});
return false;
}
if (data.code==1) {
//开始倒计时
curCount = count;
//设置button效果,开始计时
$("#send").attr("disabled", "true");
$("#send").val(curCount +"s");
InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
}
},
'json'
);
});
// timer处理函数
function SetRemainTime() {
if (curCount == 0) {
window.clearInterval(InterValObj);//停止计时器
$("#send").removeAttr("disabled");//启用按钮
$("#send").val("点击重新获取");
}else{
curCount--;
$("#send").val(curCount +"s");
}
}
/**************************************找回密码三步验证手机正则表达式 php版*******************************************/
function isPhoneNo(phone) {
var pattern = /^1[3-9]\d{9}$/;
return pattern.test(phone);
}
// 验证步骤
$('#btn_part1').click(function(){//第一步
var mobile = $.trim($('#mobile').val());//手机号
var mobile_code = $.trim($('#mobile_code').val());//手机验证码
var code_math = $.trim($('#code_math').val());//算术验证码
if(!mobile){
return layer.tips('<p style="font-size:18px;">请输入手机号!</p>', '#mobile',{ tips: [3, '#fd5004']});
}
if(!isPhoneNo(mobile)){
return layer.tips('<p style="font-size:18px;">请输入正确的手机号!</p>', '#mobile',{ tips: [3, '#fd5004']});
}
if(!code_math){
return layer.tips('<p style="font-size:18px;">请输入右侧答案!</p>', '#code_math',{ tips: [3, '#fd5004']});
}
if(!mobile_code){
return layer.tips('<p style="font-size:18px;">请输入手机验证码!</p>', '#mobile_code',{ tips: [3, '#fd5004']});
}
$.post(
"/checkcallbackcode",
{
mobile: mobile,
code: mobile_code,
code_math: code_math,
_token: "{{ csrf_token() }}"
},
function(data,textStatus){
if(data.code==3){
return layer.tips('<p style="font-size:18px;">答案输入有误!</p>', '#code_math',{ tips: [3, '#fd5004']});
}
if(data.code==0){
return layer.tips('<p style="font-size:18px;">'+data.msg+'</p>', '#btn_part1',{ tips: [3, '#fd5004']});
}
if(data.code==1){//跳转到下一步
$('#parent_2_mobile').val(mobile);
$('#mobile_two').html(mobile);
$('#btn_part1').closest('.formSub').hide().next().show().next().hide();
$('#btn_part1').closest('.cbPassword').find('.Password li').eq(1).addClass('active').siblings().removeClass('active');
}
},
"json"
);
});
$('#btn_part2').click(function(){//第二步
var mobile = $('#parent_2_mobile').val();
var password = $.trim($('#password').val());
var re_password = $.trim($('#confirm_password').val());
//var pass = /^[a-zA-Z]\w{5,17}$/;
if(!password){
return layer.tips('<p style="font-size:18px;">请输入密码</p>', '#password',{ tips: [3, '#fd5004']});
}
if(password.length<6 || password.length>20){
return layer.tips('<p style="font-size:18px;">密码长度为6-20个字符</p>', '#password',{ tips: [3, '#fd5004']});
}
if(!re_password){
return layer.tips('<p style="font-size:18px;">请确认新密码</p>', '#confirm_password',{ tips: [3, '#fd5004']});
}
if(password!=re_password){
return layer.tips('<p style="font-size:18px;">密码不一致</p>', '#confirm_password',{ tips: [3, '#fd5004']});
}
$.post(
"/changepassword",
{
mobile: mobile,
password: password,
re_password: re_password,
_token: "{{ csrf_token() }}"
},
function(data,textStatus){
if(data.code==0){
layer.tips('<p style="font-size:18px;">'+data.msg+'</p>', '#btn_part2',{ tips: [3, '#fd5004']});
}
if(data.code==1){
$('#btn_part2').closest('.formSub').hide().next().show().next().hide();
$('#btn_part2').closest('.cbPassword').find('.Password li').eq(2).addClass('active').siblings().removeClass('active')
}
},
"json"
);
})