日期:2014-05-16  浏览次数:20436 次

注册页面的一些Js验证

<script type="text/javascript">

? function regvalidation(form){
?
? var member_User = form.memberUserName.value;
? var u_s = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
? if(member_User == ""){
??? alert("请输入账号!");
??? regForm.memberUserName.focus();
??? return false;
?? }else{
??? if(!u_s.test(member_User)){
?????? alert("账号格式不正确");
?????? regForm.memberUserName.focus();
?????? return false;
??? }
?? }
?
? var true_N = form.trueName.value;
? if(true_N == ""){
??? alert("姓名不能为空!");
??? regForm.trueName.focus();
??? return false;
?? }
?
? var cer_T = form.Certificate.value;
? var len = cer_T.length;
? if(cer_T == ""){
??? alert("身份证号不能为空!");
??? regForm.Certificate.focus();
??? return false;
? }else{
??? if(len == 15 || len == 18){
??????? if(isNaN(cer_T)){
????????? alert("身份证号格式错误,请重新输入!");
????????? regForm.Certificate.focus();
????????? return false;
??????? }
??? }else{
????? alert("身份证的位数为15位或18位,请重新输入!");
????? regForm.Certificate.focus();
????? return false;
??? }
? }
??
? var pass_W = form.password.value;
? var plen = pass_W.length;
? if(pass_W == ""){
??? alert("密码不能为空!");
??? regForm.password.focus();
??? return false;
? } else{
??? if(plen < 6 || plen >= 12){
?????? alert("密码位数为6-12,请重新输入");
?????? regForm.password.focus();
?????? return false;
?????? }
? }
?
? var repass_W = form.repassword.value;
?? if(repass_W != pass_W){
???? alert("密码输入不一致!");
???? regForm.repassword.focus();
???? return false;
?? }
??
?? var pay_Pass = form.paypassword.value;
?? var relen = pay_Pass.length;
?? if(pay_Pass == ""){
???? alert("请输入支付密码!");
???? regForm.paypassword.focus();
???? return false;
?? }else{
???? if(relen < 6 || relen >= 12){
?????? alert("支付密码位数为6-12,请重新输入");
?????? regForm.repassword.focus();
?????? return false;
?????? }
?? }
??
?? var re_Pay_P = form.repaypassword.value;
?? if(re_Pay_P != pay_Pass){
???? alert("支付密码输入不一致!");
???? regForm.repaypassword.focus();
???? return false;
?? }
??
?? var mob = form.mobile.value;
?? var moblen = mob.length;
?? if(mob == ""){
???? alert("手机号码不能为空!");
???? regForm.mobile.focus();
???? return false;
?? }else{
???? if(isNaN(mob)){
?????? alert("手机号码有非法字符");
?????? regForm.mobile.focus();
?????? return false;
???? }else{
?????? if(moblen != 11){
??????? alert("手机号码格式不正确");
??????? regForm.mobile.focus();
??????? return false;
?????? }
???? }
?? }
??
?? var e_M = form.Email.value;
?? var myem = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
?? if(e_M == ""){
???? alert("邮箱不能为空");
???? regForm.Email.focus();
???? return false;
?? }else{
????? if(!myem.test(e_M)){
??????? alert("请输入正确的邮箱");
??????? regForm.Email.focus();
??????? return false;
????? }
?? }
??
?? var ques_T = form.question.value;
?? if(ques_T ==""){
???? alert("请选择问题!");
???? return false
?? }
??
?? var an_S = form.answer.value;
?? if(an_S == ""){
???? alert("请输入答案");
???? regForm.answer.focus();
???? return false;
?? }
??
?? var se_C = form.secrity.value;
?? if(se_C == ""){
???? alert("验证码不能为空");
???? regForm.secrity.focus();
???? return false;
?? }
??
??
??
?? var se_R = form.service.checked;
?? if(se_R == false){
???? alert("不同意×××协议,将无法注册!");
???? return false;
?? }
? }

</script>

?

html页面的表单:

<form name="regForm" action="..." method="post" onsubmit="javascript:return regvalidation(this);">

????? ......

??? ? ......

</form>

?

?