登录注册之前个人基本信息校验
Posted Vivianluolita
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了登录注册之前个人基本信息校验相关的知识,希望对你有一定的参考价值。
<div class="" id="mask"></div>
<div id="login_mask" class="login_mask_content">
<div class="mask_title">用户登录</div>
<form method="post" class="login_form" id="login_subform" >
<div class="login-input username">
<span>账号</span>
<input type="text" id="username" name="username" placeholder="身份证号或者注册手机号">
<input id="fwid" type="hidden" name="fwid" value="">
<input type="hidden" value="" name="menuid" id="menuid">
<a href="javascript:void(0)" onclick="fnOpenRegistWin()">注册</a>
</div>
<div class="login-input pswd">
<span>密码</span>
<input type="password" id="password" name="password" placeholder="请输入密码!">
</div>
<div class="login-input yzm" id="ptyzm">
<span>验证码</span>
<input id="captcha_gr" type="text" name="captcha" placeholder="请输入验证码!">
<img id="codeimg" style="width:60px;height:100%;border-left:solid #ddd 1px;size:100%;position:absolute;right:0" onclick="refeshCode()" title="点击换一张" src="$rootpath/CaptchaImg">
</div>
<div class="tips div-after">
<a href="javascript:void(0)" onclick="fnOpenPsdWin()">重置密码</a>
</div>
<div class="btn-content">
<a class="login-btn" id="login_btn" onclick="login()">登 录</a>
<a class="cancle-btn" onclick="fnCloseWin()">取消</a>
</div>
</form>
</div>
<div id="regist_mask" class="login_mask_content">
<div class="mask_title">注册</div>
<form method="post" class="regist_form" id="regist_subform" >
<div class="inputs idcard">
<span><i>*</i>身份证号</span>
<input type="text" onChange="validIdcard(this)" id="idcard" placeholder="请输入二代身份证号码">
</div>
<div class="inputs name">
<span><i>*</i>姓 名</span>
<input type="text" id="name" placeholder="请输入姓名!">
</div>
<div class="inputs phone">
<span><i>*</i>手机号码</span>
<input type="text" onChange="validTel()" id="tel" placeholder="请输入手机号码!">
</div>
<div class="inputs validCode">
<span><i>*</i>验 证 码</span>
<input type="text" id="validCode" placeholder="请输入短信验证码!" style="width: 160px;">
<a class="send-btn" href="javascript:;" onclick="sendCode(this,1)">发送验证码</a>
</div>
<div class="inputs pwd">
<span><i>*</i>密 码</span>
<input type="password" id="pwd" placeholder="请输入密码!">
</div>
<div class="inputs pwd_confirm">
<span><i>*</i>确认密码</span>
<input type="password" class="" id="pwd_confirm" onChange="validPwd(this)" placeholder="请输入确认密码!">
</div>
<div class="inputs tips">已有账号,<a class="toLogin-btn" onclick="fnChangeToLoginWin()">立即登录</a></div>
<div class="btn-content">
<a class="login-btn" id="register_btn" onclick="fnRegister()">注册</a>
<a class="cancle-btn" onclick="fnCloseWin()">取消</a>
</div>
</form>
</div>
<div id="password_mask" class="login_mask_content">
<div class="mask_title">重置密码</div>
<form method="post" class="password_form" id="password_subform" >
<div class="inputs phone">
<span><i>*</i>手 机 号</span>
<input type="text" id="phone1" name="phone" onChange="validIdTel1()" placeholder="请输入手机号!">
</div>
<div class="inputs validCode">
<span><i>*</i>验 证 码</span>
<input type="text" id="validCode1" placeholder="请输入短信验证码!" style="width: 144px;">
<a class="send-btn" href="javascript:;" onclick="sendCode(this,2)">发送验证码</a>
</div>
<div class="inputs idcard">
<span><i>*</i>身份证号码</span>
<input type="text" id="idcard1" onChange="validIdcard1(this)" placeholder="请输入身份证号码!">
</div>
<div class="inputs username">
<span><i>*</i>姓 名</span>
<input type="text" id="username1" name="username" placeholder="请输入姓名!">
</div>
<div class="inputs yac005" style="display:none;">
<span><i>*</i>社保 卡号</span>
<input type="text" id="yac005" name="yac005" placeholder="请输入社保卡号!">
</div>
<div class="inputs psw">
<span><i>*</i>新 密 码</span>
<input type="password" id="new_psw" name="password" placeholder="请输入新密码!">
</div>
<div class="inputs new-psw">
<span><i>*</i>确认新密码</span>
<input type="password" id="new_psw_confirm" name="password" placeholder="请输入确认新密码!" onChange="validPwd1(this)">
</div>
<div class="inputs tips"><a class="toLogin-btn" onclick="fnChangeToLoginWin()">返回登录</a></div>
<div class="btn-content">
<a class="login-btn" id="changePsw_btn" onclick="fnChangePsw()">重置密码</a>
<a class="cancle-btn" onclick="fnCloseWin()">取消</a>
</div>
</form>
</div>
<script type="text/javascript">
$(function()
//捕获回车键
$('html').bind('keydown',function(e)
if(e.keyCode==13)
var login_flag = $("#login_mask").is(':visible');
var register_flag = $("#regist_mask").is(':visible');
if(login_flag)
login();
else if(register_flag)
fnRegister();
else
fnChangePsw();
);
);
//切换到登录界面
function fnChangeToLoginWin()
$("#mask").show();
$("#regist_mask").hide();
$("#password_mask").hide();
$("#login_mask").show();
//打开登录弹框
function fnOpenLoginWin(zpType,menuid)
$("#menuid").val(menuid);
$("#mask").show();
$("#regist_mask").hide();
$("#password_mask").hide();
$("#login_mask").show();
//打开注册界面
function fnOpenRegistWin()
$("#mask").show();
$("#login_mask").hide();
$("#password_mask").hide();
$("#regist_mask").show();
//打开修改密码界面
function fnOpenPsdWin()
$("#login_mask").hide();
$("#regist_mask").hide();
$("#password_mask").show();
//关闭弹框
function fnCloseWin()
$("#mask").hide();
$("#login_mask").hide();
$("#regist_mask").hide();
$("#password_mask").hide();
window.location.reload()
//刷新验证码
function refeshCode()
document.getElementById("codeimg").src = "$rootpath/CaptchaImg?j="+ Math.random();
var timer = 60;
var clock = '';
var btn;
//发送验证码
function sendCode(obj,type)
btn = $(obj);
if(btn.hasClass("btn-disabled"))
return;
var tel = "";
if(type == 1)
tel = $("#tel").val();
else
tel = $("#phone1").val();
if(tel==''||tel==null)
Netof.alertBox("手机号不能为空!");
$("#tel").focus();
return;
btn.addClass("btn-disabled");
btn.text(timer + "秒后重试");
clock = setInterval(doLoop,1000);
$.ajax(
"url":"$rootpath/wtqt/memberCtroller/sendCode.jspx",
"async":true,
"data":"phone":tel,
"success":function(data)
if(data.fieldData.code = "1")
Netof.alertMsgTopTip("发送短信成功!");
else
Netof.alertMsgTopTip("发送短信失败!");
,
"error":function(data)
,
"type":"POST",
"dataType":"json"
);
function doLoop()
timer--;
if (timer > 0)
btn.text(timer + "秒后重试");
else
clearInterval(clock);
btn.removeClass("btn-disabled");
btn.text("发送验证码");
timer = 60;//重置时间
</script>
<!--登录js-->
<script type="text/javascript">
//登录注册之前个人基本信息校验2018-02-01
function validateBefore(flag,username)
var str = false;
if(flag==1) //手机号
$.ajax(
"url":"$rootpath/wtqt/memberCtroller/queryIdcard.jspx",
"async":false,
"data":"username":username,
"type":"POST",
"dataType":"json",
"success":function(data)
console.log(data);
if(data.success)
$.ajax(
"url":"$rootpath/xtpt/businessController/getDataNoLogin.jspx",
"async":false,
"data":"aac002":data.fieldData.aac002,"fwid":"HBSIZB10011",
"type":"POST",
"dataType":"json",
"success":function(data2)
if(data2.success)
if(data2.lists)
if(data2.lists.resultset.list.length==1)//数据正常可以登录
str = true;
else
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
else//数据有误
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
else
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
,
"error":function(data)
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
);
else
Netof.alertBox(data.resultMessage.message);
,
"error":function(data)
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
);
else
$.ajax(
"url":"$rootpath/xtpt/businessController/getDataNoLogin.jspx",
"async":false,
"data":"aac002":username,"fwid":"HBSIZB10011",
"type":"POST",
"dataType":"json",
"success":function(data2)
console.log(data2);
if(data2.success)
if(data2.lists)
if(data2.lists.resultset.list.length==1)
if(data2.lists.resultset.list[0].cn=="1")//数据正常可以登录
str = true;
else
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
else
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
else//数据有误
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
else
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
,
"error":function(data)
Netof.alertBox("请到社保大厅三楼核实个人基本资料");
);
return str;
var aab005="";
var RSAkey=getPublicKey();
//执行登录方法
function login()
var key=AESUtils.getKey();
var zplb = "2017001";
var menuid=$("#menuid").val();
var fwid=$("#fwid").val();
var username=$("#username").val();
var password=$("#password").val();
var captcha="";
var captcha_dw=$("#captcha_dw").val();
var captcha_gr=$("#captcha_gr").val();
if(username==''||username==null)
Netof.alertBox("用户名不能为空!");
$("#username").focus();
return;
if(password==''||password==null)
Netof.alertBox("请先输入密码!");
$("#captcha").focus();
return;
var loginid_type='';
var usertype = "个人用户";
if(usertype=="个人用户")
if(captcha_gr==''||captcha_gr==null)
Netof.alertBox("请输入图形验证码!");
$("#password").focus();
return;
captcha=captcha_gr;
var partten = /^1[3,5,4,7,8]\\d9$/;
if (partten.test(username))
loginid_type='tel';
else
loginid_type='idcard';
usertype="aac001";
logining(true);
var cFlag = false;
if(loginid_type=="tel")
cFlag=validateBefore(1,username);
else
cFlag=validateBefore(2,username);
if(!cFlag)
logining(false);
return;
var parameter = "username="+(username.length>0?RSAUtils.encryptedString(RSAkey,decodeURIComponent(username)) :"")+"&password="+(password.length>0?RSAUtils.encryptedString(RSAkey,decodeURIComponent(password)) :"")+"&checkCode="+captcha+"&loginidtype="+loginid_type+"&zplb="+zplb;
$.ajax(
"url":"$rootpath/wtqt/memberCtroller/loginNew.jhtml",
"async":true,
"data":parameter,
"success":function(data, textStatus, jqXHR)
//console.log(data);
var sjcode=data.fieldData.code;
if(sjcode=="1")
if(menuid == "123740")
window.open("$rootpath/hbsyldyzm/index.jhtml");
else if(menuid == "123741")
window.open("$rootpath/hbsylbxlncbjfzm/index.jhtml");
else if(menuid == "123742")
window.open("$rootpath/jxylbxgxtzd/index.jhtml");
else if(menuid == "123743")
window.open("$rootpath/jbylbxcbjfpz/index.jhtml");
else if(menuid == "123744")
window.open("$rootpath/hbsshbxcbzm(grzy)/index.jhtml");
else if(menuid == "123745")
window.open("$rootpath/hbsshbxcbzm/index.jhtml");
else if(menuid == "123746")
window.open("$rootpath/ndylbxgrqyjld/index.jhtml");
window.location.reload();
else
var message=data.resultMessage.message;
Netof.alertBox(message);
logining(false);
return;
,
"error":function(data, textStatus, jqXHR)
Netof.alertBox("请刷新页面重试!");
Netof.hideMask();
return;
,
"complete":function(_XMLHTTPRequest,textStatus)
return ;
,
"type":"POST",
"dataType":"json"
);
//登录中...
function logining(allow)
//改变背景色和字
if (allow)
$("#login_btn").css('background-color':'#ddd',"cursor":"not-allowed","border":"none").text("登录中...").attr("onclick","");
else
$("#login_btn").css('background-color':'#3B84E2',"cursor":"pointer").text("登录").attr("onclick","login()");
function getPublicKey()
var RSAkey;
var param=
$.ajax(
"url":"$rootpath/getRSAKey.jspx",
"async":false,
"data":param,
"success":function(data, textStatus, jqXHR)
if(!data.success)
return ;
var publicKeyExponent=data.fieldData.publicKeyExponent;
var publicKeyModulus=data.fieldData.publicKeyModulus;
RSAkey=new RSAUtils.getKeyPair(publicKeyExponent, "", publicKeyModulus);//生成rsa公钥
,
"error":function(data, textStatus, jqXHR)
return;
,
"complete":function(_XMLHTTPRequest,textStatus)
return ;
,
"type":"POST",
"dataType":"json"
);
return RSAkey;
</script>
<!--注册js-->
<script type="text/javascript">
//身份证验证
function validIdcard()
var idcard = $("#idcard").val();
if(idcard.trim()=="")
Netof.alertBox("身份证不能为空");
Netof.setValue("idcard","");
$("#idcard").focus();
return;
if(validataIdcard(idcard,"idcard"))//如果身份证合法,则校验是否已经注册
Netof.submit("","$rootpath/wtqt/memberCtroller/checkUserExit.jhtml","code":idcard,"",function(data)
if(data.fieldData.code=="1")
pass = true;
var flag = validateBefore(2,idcard);
if(!flag)
Netof.setValue("idcard","");
$("#idcard").focus();
else
Netof.alertBox("对不起,你输入的身份证号:"+idcard+"已经注册");
Netof.setValue("idcard","");
$("#idcard").focus();
pass = false;
,null,null,null,null,null,true);
//电话号码验证
function validTel()
var _cell = $('#tel').val();
var partten = /^1[3,5,4,7,8]\\d9$/;
if(partten.test(_cell))
var pass;
Netof.submit("","$rootpath/wtqt/memberCtroller/checkUserExit.jhtml","username":_cell,"",function(data)
if(data.fieldData.code=="1")
pass = true;
else
Netof.alertBox("对不起,你输入的手机号:"+_cell+"已经注册");
Netof.setValue("tel","");
$("#tel").focus();
pass = false;
,null,null,null,null,null,true);
return pass;
else
Netof.alertBox("请输入正确的手机号","","warn");
$('#tel').val("");
return false;
//邮箱验证
function validEmail()
var _email = $("#email").val();
var _filter = /^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]2,4)+$/;
if(_filter.test(_email))
return true;
else
Netof.alertBox("请输入正确邮箱","","warn");
Netof.setValue("email","");
return false;
//密码验证
function validPwd(obj)
var _id = $(obj).id;
var _pwd = $('#pwd').val();
var _pwd_c = $('#pwd_confirm').val();
if(_pwd != _pwd_c)
Netof.alertBox("两次输入的密码不一致","","warn");
return false;
else
return true;
//重复密码是否相同验证
function validPwd_c()
var _pwd = $('.input_pwd input').val();
var _confirm_pwd = $('.confirm_pwd input').val();
if (_pwd==_confirm_pwd)
return true;
else
Netof以上是关于登录注册之前个人基本信息校验的主要内容,如果未能解决你的问题,请参考以下文章