function chkcard(){ //15位和18位身份证号码的正则表达式 var idcard=document.getelementbyid("card").value; var regidcard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[xx])$)$/; //如果通过该验证,说明身份证格式正确,但准确性还需计算 if(regidcard.test(idcard)){ if(idcard.length==18){ var idcardwi=new array( 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ); //将前17位加权因子保存在数组里 var idcardy=new array( 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ); //这是除以11后,可能产生的11位余数、验证码,也保存成数组 var idcardwisum=0; //用来保存前17位各自乖以加权因子后的总和 for(var i=0;i<17;i++){ idcardwisum+=idcard.substring(i,i+1)*idcardwi[i]; } var idcardmod=idcardwisum%11;//计算出校验码所在数组的位置 var idcardlast=idcard.substring(17);//得到最后一位身份证号码 //如果等于2,则说明校验码是10,身份证号码最后一位应该是x if(idcardmod==2){ if(idcardlast=="x"||idcardlast=="x"){ // alert("恭喜通过验证啦!"); text_msg.style.display = "none"; return true; }else{ text_msg.innerhtml = "身份证号码错误!"; text_msg.style.display = "block"; return false; } }else{ //用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码 if(idcardlast==idcardy[idcardmod]){ text_msg.style.display = "none"; return true; }else{ text_msg.innerhtml = "身份证号码错误!"; text_msg.style.display = "inline"; return false; } } } }else{ if(idcard==''){ text_msg.innerhtml = "身份证号码不能为空!"; text_msg.style.display = "inline"; return false; } text_msg.innerhtml = "身份证号码格式不正确!"; text_msg.style.display = "inline"; return false; } } /* * 只能是中文汉字 */ function chkxm(){ var xmvalue=document.getelementbyid("xm").value; var aa=/^[\u4e00-\u9fa5]+$/; if(xmvalue==''){ text_xm.innerhtml = "姓名不能为空!"; text_xm.style.display = "inline"; return false; }else{ if(aa.test(xmvalue)){ text_xm.style.display = "none"; return true; } text_xm.innerhtml = "姓名只能为汉字!"; text_xm.style.display = "inline"; return false; } } function chkdh(){ var xmvalue=document.getelementbyid("dh").value; var aa=/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/; if(xmvalue==''){ text_dh.innerhtml = "联系电话不能为空!"; text_dh.style.display = "inline"; return false; }else{ if(aa.test(xmvalue)){ text_dh.style.display = "none"; return true; } text_dh.innerhtml = "联系电话有误!"; text_dh.style.display = "inline"; return false; } } function chkmz(){ var xmvalue=document.getelementbyid("mz").value; if(xmvalue==''){ text_mz.innerhtml = "民族不能为空!"; text_mz.style.display = "inline"; return false; }else{ text_mz.style.display = "none"; return true; } } function chkqq(){ var xmvalue=document.getelementbyid("qq").value; if(xmvalue==''){ text_qq.innerhtml = "qq或e-mail不能为空!"; text_qq.style.display = "inline"; return false; }else{ text_qq.style.display = "none"; return true; } } function chkfrm(f){ if(chkxm(f.xm)==false || chkcard(f.card)==false || chkdh(f.dh)==false || chkmz(f.mz)==false || chkqq(f.qq)==false){ return false; }else{ return true; } }