register.php,register.php

用户注册

验证码不正确

登 录

$(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

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值