验证码不正确
$(function() {
var layer = layui.layer
$("#change").click(function(e) {
e.preventDefault();
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
})
$('#submit').click(function() {
var username = $('#username').val(),
password = $('#password').val(),
repassword = $('#repassword').val(),
nick = $('#nick').val(),
authcode = $('#authcode').val();
if (username == '' || username.length <= 0) {
layer.tips('用户名不能为空', '#username', {
time: 2000,
tips: 2
});
$('#username').focus();
return false;
}
if (username.length < 6 || username.length > 16) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('用户名长度必须为6到16位字符', '#username', {
time: 2000,
tips: 2
});
$('#username').focus();
return false;
}
if (nick == '' || nick.length <= 0) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('昵称不能为空', '#nick', {
time: 2000,
tips: 2
});
$('#nick').focus();
return false;
}
if (nick.length < 2 || nick.length > 10) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('昵称长度必须为2到10位字符', '#nick', {
time: 2000,
tips: 2
});
$('#nick').focus();
return false;
}
if (password == '' || password.length <= 0) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('密码不能为空', '#password', {
time: 2000,
tips: 2
});
$('#password').focus();
return false;
}
if (password.length < 6 || password.length > 16) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('密码长度必须为6到16位字符', '#password', {
time: 2000,
tips: 2
});
$('#password').focus();
return false;
}
if (repassword == '' || repassword.length <= 0 || (password != repassword)) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('两次密码输入不一致', '#repassword', {
time: 2000,
tips: 2
});
$('#repassword').focus();
return false;
}
if (repassword.length < 6 || repassword.length > 16) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('密码长度必须为6到16位字符', '#password', {
time: 2000,
tips: 2
});
$('#password').focus();
return false;
}
if (authcode.length == '' || authcode.length <= 0) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('验证码长度必须为4位', '#authcode', {
time: 2000,
tips: 4
});
$('#authcode').focus();
return false;
}
if (authcode.length != 4) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('验证码长度必须为4位', '#authcode', {
time: 2000,
tips: 4
});
$('#authcode').focus();
return false;
}
$.ajax({
type: "POST",
url: "model/login/register.php",
data: {
username: $("#username").val(),
password: $("#password").val(),
authcode: $("#authcode").val(),
nick: $("#nick").val(),
repassword: $("#repassword").val()
},
dataType: "json",
success: function(data) {
console.log(data)
if (data.code == 0) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('验证码错误', '#authcode', {
time: 2000,
tips: 4
});
} else if (data.code == 1) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('用户名已被注册', '#username', {
time: 2000,
tips: 2
});
} else if (data.code == 2) {
layer.confirm('恭喜您!注册成功!', {
btn: ['去登录', '关闭'] //按钮
}, function() {
window.location = "index.php"
}, function() {});
} else if (data.code == 3) {
$("#captcha_img").attr("src", 'public/captcha.php?r=' + Math.random());
layer.tips('昵称已被注册', '#nick', {
time: 2000,
tips: 2
});
} else {
layer.alert('注册失败!,再试一次!');
}
}
})
return true;
})
})
一键复制
编辑
Web IDE
原始数据
按行查看
历史