$(function(){
var checkedByVerifyCode = false;
var checkMobieCode = false;
var checkedMobile = false;
var checkedEmail = false;
var checkedLoginName = false;
window.captcha = function(obj) {
obj.src = "/captcha/index.do?randdate=" + Math.random();
}
window.checkcode = function(){
if($("#login_code").val()==""){
$(‘#verify_code_error‘).html("<div class=‘member-error-message‘>*请输入正确的验证码!</div>");
$(‘#verify_code_error‘).show(400);
} else {
$(‘#verify_code_error‘).html("");
$(‘#verify_code_error‘).hide(400);
}
}
function distoshow(e,ltime){
e.attr(‘disabled‘,true);
var lefttime = parseInt(ltime);
var tmpstr = e.attr("value");
var tmpt = setInterval(function(){
lefttime--;
if(lefttime > 0){
e.attr("value",lefttime + "秒后重新发送");
}else{
e.attr(‘value‘,tmpstr);
e.attr(‘disabled‘,false);
clearInterval(tmpt);
return;
}
},1000);
}
//验证密码
function checkPass(passWord){
var memberPass = /^[a-zA-Z0-9_]{6,20}$/;
//var memberPass = /^(?=.*[0-9].*)(?=.*[a-zA-Z].*).{6,20}$/;
var numPass = /^[0-9]+$/;
if(passWord == ‘‘){
$("#passWord").empty().hide();
$("#MemberBase_pass_em_").empty().append(‘*密码不能空!‘).show();
return false;
}
if(numPass.test(passWord)){
$("#passWord").empty().hide();
$("#MemberBase_pass_em_").empty().append(‘*密码不能为纯数字!‘).show();
return false;
}else{
$("#MemberBase_pass_em_").empty().hide();
}
var pass = memberPass.test(passWord);
if(!pass){
$("#passWord").empty().hide();
$("#MemberBase_pass_em_").empty().append(‘*密码必须包含字母和数字且必须在6-20个字符以内!‘).show();
return false;
}else{
$("#MemberBase_pass_em_").empty().hide();
return true;
}
}
//校验密码确认
function checkPassRepeat(Password,PasswordRepeat){
if(Password != PasswordRepeat){
$("#MemberBase_pass_repeat_em_").empty().append(‘*确认密码输入不一致!‘).show();
return false;
}else{
$("#MemberBase_pass_repeat_em_").empty().hide();
return true;
}
}
//校验验证码
function checkVerifyCode(verifyCode,email){
$.post("/member/checkEmailCode.do",{ verifyCode:verifyCode,email:email},function(json){
if(json.status){
$("#MemberBase_verifyCode_em_").empty().hide();
checkedByVerifyCode = true;
return true;
}else{
$("#MemberBase_verifyCode_em_").empty().append(‘*‘+json.statusinfo).show();
checkedByVerifyCode = false;
return false;
}
},‘json‘);
}
//用户名检验
$(‘.login_name‘).focusout(function(){
var loginName = $.trim($(‘.login_name‘).val());
if(loginName == ‘‘){
$("#loginName").empty().hide();
$(‘#member_UserName‘).empty().hide();
$("#MemberBase_login_name_em_").empty().append(‘*账户名不能为空‘).show();
return false;
}
$.post("/member/checkLoginName.do",
{ loginName:loginName },function(json){
if(json.status){
$("#MemberBase_login_name_em_").empty().hide();
checkedLoginName = true;
return true;
}else{
$("#loginName").empty().hide();
$(‘#member_UserName‘).empty().hide();
$("#MemberBase_login_name_em_").empty().append(‘*‘+json.statusinfo).show();
checkedLoginName = false;
return false;
}
},‘json‘);
});
//用户密码校验
$(‘.member_pass‘).focusout(function(){
var passWord = $.trim($(‘.member_pass‘).val());
checkPass(passWord);
});
//密码确认校验
$(‘.member_pass_repeat‘).focusout(function(){
var Password = $.trim($(‘.member_pass‘).val());
var PasswordRepeat = $.trim($(‘.member_pass_repeat‘).val());
$(this).closest(‘td‘).find(‘.message-error‘).remove();
checkPassRepeat(Password, PasswordRepeat);
});
//手机号码校验
$(‘.member_mobile‘).focusout(function(){
var mobile = $.trim($(‘.member_mobile‘).val());
var phoneReg=/^0?1[3584][0-9][0-9]{8}$/;
if(!phoneReg.test(mobile)){
$("#MemberBase_mobile_em_").empty().append(‘*请确认输入的是手机号‘).show();
return false;
}else{
$("#MemberBase_mobile_em_").empty().hide();
}
$(‘#getPhoneCode‘).unbind(‘click‘);
$(‘#getPhoneCode‘).click(function(){
$.post("/member/mobileToken.do",{ mobile: mobile },function(json){
if(json.status){
distoshow($(‘#getPhoneCode‘),60);
checkedMobile = true;
$(‘#mobile_token‘).attr(‘value‘,json.mobile_token);
$(‘#check_token‘).attr(‘value‘,json.check_token);
$(‘#registeType‘).attr(‘value‘,‘mobile‘);
}else{
$("#MemberBase_mobile_em_").empty().append(‘*‘+json.statusinfo).show();
checkedMobile = false;
return false;
}
},‘json‘);
});
});
//手机验证码校验
$(‘.mobile_code‘).focusout(function(){
var mobileCode = $.trim($(‘.mobile_code‘).val());
var mobile = $.trim($(‘.member_mobile‘).val());
$.post("/member/checkMobileCode.do",{ mobileCode:mobileCode,mobile:mobile},function(json){
if(json.status){
$("#MemberBase_mobile_code_em_").empty().hide();
checkMobieCode = true;
$(‘#validateByClient‘).val(‘true‘);
}else{
$("#MemberBase_mobile_code_em_").empty().append(‘*‘+json.statusinfo).show();
checkMobieCode = false;
return false;
}
},‘json‘);
});
//用户邮箱验证
$(‘.member_email‘).focusout(function(){
var email = $.trim($(‘.member_email‘).val());
var emailReg=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
if(!emailReg.test(email)){
$("#MemberBase_email_em_").empty().append(‘*请确认输入的是邮箱‘).show();
return false;
}else{
$("#MemberBase_email_em_").empty().hide();
}
$.post("/member/checkEmail.do",{email:email},function(json){
if(json.status){
$("#MemberBase_email_em_").empty().hide();
checkedEmail = true;
return true;
}else{
$("#MemberBase_email_em_").empty().append(‘*‘+json.statusinfo).show();
checkedEmail = false;
return false;
}
},‘json‘);
});
//校验码验证
$(‘.register_box .verifyCode‘).change(function(){
var verifyCode = $.trim($(this).val());
var email = $.trim($(‘.member_email‘).val());
$.post("/member/checkEmailCode.do",{verifyCode:verifyCode,email:email},function(json){
if(json.status){
$("#MemberBase_verifyCode_em_").empty().hide();
checkedByVerifyCode = true;
$(‘#validateByClient‘).val(true);
return true;
}else{
$("#MemberBase_verifyCode_em_").empty().append(‘*‘+json.statusinfo).show();
checkedByVerifyCode = false;
return false;
}
},‘json‘);
});
//校验协议
$(‘#MemberBase_rules‘).click(function(){
if(!$("#MemberBase_rules").attr("checked")){
$("#MemberBase_rules_em_").empty().append(‘*您必须同意该协议‘).show();
}else{
$("#MemberBase_rules_em_").empty().hide();
}
});
//校验协议
function checkRules(){
if(!$("#MemberBase_rules").attr("checked")){
$("#MemberBase_rules_em_").empty().append(‘*您必须同意该协议‘).show();
return false;
}else{
$("#MemberBase_rules_em_").empty().hide();
return true;
}
}
//表单提交验证
$(‘form‘).submit(function(){
var loginName = $.trim($(‘.login_name‘).val());
var passWord = $.trim($(‘.member_pass‘).val());
var Password = $.trim($(‘.member_pass‘).val());
var PasswordRepeat = $.trim($(‘.member_pass_repeat‘).val());
var mobile = $.trim($(‘.member_mobile‘).val());
var mobileCode = $.trim($(‘.mobile_code‘).val());
var verifyCode = $.trim($(‘.register_box .verifyCode‘).val());
var email = $.trim($(‘.member_email‘).val());
var index = $.trim($(‘#index‘).val());
if(loginName == ‘‘ || !checkedLoginName){
$("#MemberBase_login_name_em_").empty().append(‘*账户名错误‘).show();
$("#loginName").empty();
$(‘#member_UserName‘).empty().hide();
return false;
}else{
$("#MemberBase_login_name_em_").empty().hide();
}
if(!checkPass(passWord)){
return false;
}
if(!checkPassRepeat(Password, PasswordRepeat)){
return false;
}
if(index == 1){
if(mobileCode == ‘‘ || !checkMobieCode){
$("#MemberBase_mobile_code_em_").empty().append(‘*验证码错误‘).show();
return false;
}else{
$("#MemberBase_mobile_code_em_").empty().hide();
}
}
if(index == 2){
if($(‘.member_email‘).val() == ‘‘ || !checkedEmail){
$("#MemberBase_email_em_").empty().append(‘*请确认输入的是邮箱!‘).show();
return false;
}else{
$("#MemberBase_email_em_").empty().hide();
}
//验证码读取验证码是否为空,如果为空视为不合法
if($(‘.register_box .verifyCode‘).val() == ‘‘ || !checkedByVerifyCode){
$("#MemberBase_verifyCode_em_").empty().append(‘*验证码错误‘).show();
return false;
}else{
$("#MemberBase_verifyCode_em_").empty().hide();
}
}
if(!checkRules()){
return false;
}
});
$(‘.Eminl_button‘).hide();
$(‘.register_left‘).find(‘div‘).click(function(){
$(‘.member-error-message‘).hide();
var index = $(this).index();
//phone_title 选中状态 email_title未选中状态
$(this).addClass(‘phone_title‘).removeClass(‘email_title‘).siblings().addClass(‘email_title‘).removeClass(‘phone_title‘);
if(index == 0 ){
$(‘#index‘).val(‘1‘);
$(‘.phone-code‘).show();
$(‘.Eminl‘).hide();
$(‘.mobile_button‘).show();
$(‘.Eminl_button‘).hide();
}else{
$(‘#index‘).val(‘2‘);
$(‘.phone-code‘).hide();
$(‘.Eminl‘).show();
$(‘.mobile_button‘).hide();
$(‘.Eminl_button‘).show();
}
});
});