<script>
var US = true;
var PS = true;
var RPS = true;
var PH = true;
var CV = true;
// 验证码倒计时
var countdown=60;
function settime(obj) { //发送验证码倒计时
if (countdown == 0) {
obj.attr('disabled',false);
//obj.removeattr("disabled");
obj.val("获取验证码");
countdown = 60;
return;
} else {
obj.attr('disabled',true);
obj.val("重新发送(" + countdown + ")");
countdown--;
}
setTimeout(function() {
settime(obj) }
,1000)
}
//用户名
//获取焦点事件
$('input[name=aname]').focus(function(){
// $(this).css('border','solid 1px skyblue');
$(this).addClass('cur');
})
//失去焦点事件
$('input[name=aname]').blur(function(){
//获取输入的值
var uv = $(this).val().trim();
if(uv == ''){
$(this).next().text(' *用户名不能为空').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
US = false;
return;
}
//正则
var reg = /^\w{6,16}$/;
var tu = $(this);
//检测
if(!reg.test(uv)){
$(this).next().text(' *用户名格式不正确').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
US = false;
} else {
//发送ajax
$.post('/home/checkuser',{aname:uv},function(data){
//判断
if(data == '1'){
tu.next().text(' *用户名已存在').css('color','#e53e41');
tu.css('border','solid 1px #e53e41');
US = false;
} else {
tu.next().text(' *√').css('color','green');
tu.css('border','solid 1px green');
US = true;
}
})
}
})
//密码
$('input[name=password]').focus(function(){
$(this).addClass('cur');
})
//失去焦点
$('input[name=password]').blur(function(){
var pv = $(this).val();
if(pv == ''){
$(this).next().text(' *密码不能为空').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
PS = false;
return;
}
var reg = /^\S{6,12}$/;
if(!reg.test(pv)){
$(this).next().text(' *密码格式不正确').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
PS = false;
} else {
$(this).next().text(' *√').css('color','green');
$(this).css('border','solid 1px green');
PS = true;
}
})
//确认密码
$('input[name=repassword]').focus(function(){
$(this).addClass('cur');
})
//失去焦点
$('input[name=repassword]').blur(function(){
//获取密码
var pvs = $('input[name=password]').val().trim();
//获取确认密码
var rpv = $(this).val().trim();
if(rpv == ''){
$(this).next().text(' *确认密码不能为空').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
RPS = false;
return;
}
if(pvs != rpv){
$(this).next().text(' *两次密码不一致').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
RPS = false;
} else {
$(this).next().text(' *√').css('color','green');
$(this).css('border','solid 1px green');
RPS = true;
}
})
//手机号
$('input[name=phone]').focus(function(){
$(this).addClass('cur');
})
$('input[name=phone]').blur(function(){
var phv = $(this).val().trim();
if(phv == ''){
$(this).next().text(' *手机号不能为空').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
PH = false;
return;
}
var reg = /^1[3456789]\d{9}$/;
if(!reg.test(phv)){
$(this).next().text(' *手机号格式不正确').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
PH = false;
} else {
$.post('/home/checkrephone',{phone:phv},function(data){
if (data == '1') {
$('input[name=phone]').next().text(' *手机已被注册').css('color','#e53e41');
$('input[name=phone]').css('border','solid 1px #e53e41');
PH = false;
} else {
$('input[name=phone]').next().text(' *√').css('color','green');
$('input[name=phone]').css('border','solid 1px green');
PH = true;
}
})
}
})
//获取验证码
$('#but').click(function(){
//获取手机号
var phone = $('input[name=phone]').val().trim();
var phv = $('input[name=phone]').val().trim();
if(phv == ''){
$('input[name=phone]').next().text(' *手机号不能为空').css('color','#e53e41');
$('input[name=phone]').css('border','solid 1px #e53e41');
PH = false;
return;
}
var reg = /^1[3456789]\d{9}$/;
if(!reg.test(phv)){
$('input[name=phone]').next().text(' *手机号格式不正确').css('color','#e53e41');
$('input[name=phone]').css('border','solid 1px #e53e41');
PH = false;
} else {
$.post('/home/checkrephone',{phone:phv},function(data){
if (data == '1') {
$('input[name=phone]').next().text(' *手机已被注册').css('color','#e53e41');
$('input[name=phone]').css('border','solid 1px #e53e41');
PH = false;
} else {
var obj = $('#but');
settime(obj);
$('input[name=phone]').next().text(' *√').css('color','green');
$('input[name=phone]').css('border','solid 1px green');
PH = true;
// 发送ajax
$.post('/home/checkphone',{number:phone},function(data){
console.log(data);
})
}
})
}
})
//获取验证码
$('input[name=code]').focus(function(){
$(this).addClass('cur');
})
$('input[name=code]').blur(function(){
///获取验证码
var cd = $(this).val().trim();
if(cd == ''){
$(this).next().next().text(' *验证码不能为空').css('color','#e53e41');
$(this).css('border','solid 1px #e53e41');
CV = false;
return;
}
var cs = $(this);
//发送ajax
$.post('/home/checkcode',{code:cd},function(data){
console.log(data);
if(data == '0'){
cs.next().next().text(' *验证码不正确').css('color','#e53e41');
cs.css('border','solid 1px #e53e41');
CV = false;
} else {
cs.next().next().text(' *√').css('color','green');
cs.css('border','solid 1px green');
CV = true;
}
})
})
//提交事件
/*$(':submit').click(function(){
alert(1234);
return false;
})*/
$('#forms').submit(function(){
$('input[name=code]').trigger('blur');
$('input[name=phone]').trigger('blur');
$('input[name=repassword]').trigger('blur');
$('input[name=password]').trigger('blur');
$('input[name=aname]').trigger('blur');
if(US && PS && RPS && PH && CV){
return true;
}
//var flag = 1 var flag = 0
return false;
})
</script>