//身份证验证
function IdcardValidator(controller,label,empty,format,scope,disabled,readonly,calculateExp){
this.Validator = Validator;
this.Validator(controller,label,empty,format,scope,disabled,readonly,calculateExp);
this.disableImeMode();
}
IdcardValidator.prototype = new Validator;
IdcardValidator.prototype.constructor = IdcardValidator;
IdcardValidator.prototype.onKeyDown = function(){
var keyCode = window.event.keyCode;
if(this.getValue().length>=18){
window.event.returnValue = false;
return;
}
if(isNumber(keyCode)){
return;
}
if(this.getValue().length==17){
if(keyCode==88){
return;
}
}
window.event.returnValue = false;
return;
};
IdcardValidator.prototype.validateBirthday=function(cardNum){
//判断出生年月
if(cardNum.length!=18&&cardNum.length!=15)
return false;
var birthy;
var birthm;
var birthd;
if(cardNum.length==18){
birthy = parseInt(cardNum.substring(6,10),10);
birthm = parseInt(cardNum.substring(10,12),10);
birthd = parseInt(cardNum.substring(12,14),10);
}else{
birthy = parseInt("19" + cardNum.substring(6,8));
birthm = parseInt(cardNum.substring(8,10),10);
birthd = parseInt(cardNum.substring(10,12),10);
}
var nowdate=new Date();
var nowy=nowdate.getYear();
var nowm=nowdate.getMonth()+1;
var nowd=nowdate.getDate();
//出生年月日应该小于当前日期并且应在1900年以后
if(birthy>nowy||(birthy==nowy&&birthm>nowm)||(birthy==nowy&&birthm==nowm&&birthd>nowd)){
this.setErrorInfor("警告:[" + this.label + "]出生日期不能大于当前日期!");
return false;
}
if(birthy<1900){
this.setErrorInfor("警告:[" + this.label + "]出生年份不能小于1900年!");
return false;
}
//非法月日
if(birthm>12){
this.setErrorInfor("警告:[" + this.label + "]出生月份不能大于12!");
return false;
}
if(birthd>31){
this.setErrorInfor("警告:[" + this.label + "]的出生日不能大于31!");
return false;
}
//润年时2月应<=29
if ((birthy % 4 == 0 || birthy % 100 != 0 )||birthy % 400 == 0){
if(birthm==2){
if(birthd>29){
this.setErrorInfor("警告:[" + this.label + "]出生年" + birthy + "为润年,2月不能大于29日!");
return false;
}
}
}else{
if(birthm==2){
if(birthd>28){
this.setErrorInfor("警告:[" + this.label + "]出生年为非润年,2月不能大于28日!");
return false;
}
}
}
if(birthm==1||birthm==3||birthm==5||birthm==7||birthm==8||birthm==10||birthm==12 ){
if(birthd>31){
this.setErrorInfor("警告:[" + this.label + "]出生月为" + birthm + ",出生日不能大于31日!");
return false;
}
}else if(birthd>30){
this.setErrorInfor("警告:[" + this.label + "]出生月为" + birthm + ",出生日不能大于30日!");
return false;
}
return true;
};
IdcardValidator.prototype.validateCheckCode = function(cardNum){
if(cardNum.length<18)
return true;
//校验码是正确的---
var wi=new Array([7],[9],[10],[5],[8],[4],[2],[1],[6],[3],[7],[9],[10],[5],[8],[4],[2]);
//注意yid的第三位为X
var yid=new Array([1],[0],[44],[9],[8],[7],[6],[5],[4],[3],[2]);
var ysum=0;
var len =17;
var lastPos= cardNum.charAt(17);
for(var i=0;i<len;i++){
ysum+=parseInt(cardNum.charAt(i))*wi[i];
}
var yesno=ysum % 11;
if(yesno==2){
if(lastPos!='X'&&lastPos!='x'){
return false;
}
}else{
if(parseInt(lastPos)!=yid[yesno]){
return false;
}
}
return true;
//end校验码是正确的---
};
IdcardValidator.prototype.validate = function(){
var cardnum = this.getValue();
var len=cardnum.length;
var r15,r18,r171,re;
re = /^\d{15}$/g;
r15 = cardnum.match(re);
re=/(^\d{18}$)|(^(\d{17}(x|X)))/g;
r18 = cardnum.match(re);
if(r15==null && r18==null){
this.setErrorInfor("警告:[" + this.label + "]只能输入15位或18位数字,18位末尾允许为x或X.");
return false;
}
if(!this.validateBirthday(cardnum)){
return false;
}
if(!this.validateCheckCode(cardnum)){
this.setErrorInfor("警告:[" + this.label + "]校验失败.");
return false;
}
return true;
}
相应JSP:
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/cvicse-param.tld" prefix="param"%>
<%@ taglib uri="/WEB-INF/cvicse-common.tld" prefix="common"%>
<%@ page import="com.cvicse.util.page.PageCondition"%>
<%@ page contentType="text/html; charset=GBK"%>
<%
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
%>
<html:html>
<head>
<title></title>
<script language="javascript">
function checkDate(){
var currentDate = new Date();
var takeDate = document.forms[0].takeDate.value;
var takeDate = new Date(takeDate.replace("-","/"));
if(currentDate.getTime()<= takeDate.getTime()){
alert("警告:[上任时间]不能大于当前日期,请重新输入!");
document.forms[0].takeDate.value="";
}
}
function add(){
with(document.forms[0]){
if(cardType.value=="" && cardNo.value!=""){
alert("警告:请选择您的证件类型!");
return false;
}
operAtt.value="toAdd";
submit();
}
}
function forBack(){
document.forms[0].validatorGroup.needEmptyValidate=false;
document.forms[0].validatorGroup.needValidate=false;
document.forms[0].operAtt.value="toQuery";
document.forms[0].submit();
}
function toSubmit(sign){
with(document.forms[0]){
validatorGroup.needEmptyValidate=false;
validatorGroup.needValidate=false;
operAtt.value=sign;
submit();
}
}
</script>
<common:theme />
</head>
<body>
<common:form action="/ciMgrBasInfoAction.do" >
<html:hidden property="operAtt" styleId="operAtt"/>
<html:hidden property="custId1" styleId="custId1" />
<html:hidden property="mgrType1" styleId="mgrType1" />
<html:hidden property="mgrId1" styleId="mgrId1" />
<html:hidden property="hereWorkTime1" styleId="hereWorkTime1" />
<html:hidden property="status1" styleId="status1" />
<html:hidden property="cpo.custId" styleId="custId" />
<html:hidden property="cpo.seqNo" styleId="seqNo" />
<html:hidden property="cpo.inputDate" styleId="inputDate" />
<html:hidden property="cpo.inputMan" styleId="inputMan" />
<html:hidden property="upFlag" styleId="upFlag" />
<table class="border" align="center">
<thead>
<tr>
<td class="pagehead">新增管理层信息</td>
</tr>
</thead>
<TR><TD><html:errors /></TD></TR>
<tr>
<td>
<table width="100%" class="free" align="center">
<tr>
<td colspan="4" class="regionhead">管理层信息</td>
</tr>
<tr>
<th>管理人员客户号</th>
<td><bean:write name="ciMgrBasInfoForm" property="cpo.custId"/></td>
<th>管理人员姓名</th>
<td><common:text empty="false" label="管理人员姓名"
name="ciMgrBasInfoForm" property="cpo.mgrId" styleId="mgrId"
validator="text(0,60)" /></td>
</tr>
<tr>
<th>管理人员证件类型</th>
<td><param:select name="ciMgrBasInfoForm" label="管理人员证件类型"
type="cmisci.cardType" property="cpo.cardType" styleId="cardType"
nullStr="--请选择--" onchange="toSubmit('getValue')"/></td>
<th>管理人员证件号码</th>
<logic:notEqual name="ciMgrBasInfoForm" property="cpo.cardType" value="0000">
<td><common:text empty="true" label="管理人员证件号码"
name="ciMgrBasInfoForm" property="cpo.cardNo" styleId="cardNo"
validator="text(0,20)" /></td>
</logic:notEqual>
<logic:equal name="ciMgrBasInfoForm" property="cpo.cardType" value="0000">
<td><common:text empty="true" label="管理人员证件号码"
name="ciMgrBasInfoForm" property="cpo.cardNo" styleId="cardNo"
validator="idcard" /></td>
</logic:equal>
</tr>
<tr>
<th>管理人员出生日期</th>
<td><common:canlendarInput empty="true" label="管理人员出生日期"
name="ciMgrBasInfoForm" property="cpo.birth" size="10"
styleId="birth" validator="date(yyyy-mm-dd)"
/></td>
<th>管理人员国籍</th>
<td><param:select name="ciMgrBasInfoForm" label="管理人员国籍"
type="cmisci.nationality" property="cpo.nationality" styleId="nationality"
nullStr="--请选择--" /></td>
</tr>
<tr>
<th>管理人员学历</th>
<td><common:text empty="true" label="管理人员学历"
name="ciMgrBasInfoForm" property="cpo.educationLevel"
styleId="educationLevel" validator="text(0,20)"
/></td>
<th>管理人员联系电话</th>
<td><common:text empty="true" label="管理人员联系电话"
name="ciMgrBasInfoForm" property="cpo.teleNo"
styleId="teleNo" validator="telephone"
/></td>
</tr>
<tr>
<th>高管类别</th>
<td><param:select name="ciMgrBasInfoForm" label="高管类别" empty="false"
type="cmisci.mgrType" property="cpo.mgrType" styleId="mgrType"
nullStr="--请选择--" /></td>
<th>是否企业股东</th>
<td><param:select name="ciMgrBasInfoForm" label="是否企业股东" empty="false"
type="cmisci.isShareHolder" property="cpo.isShareHolder" styleId="isShareHolder"
nullStr="--请选择--" /></td>
</tr>
<tr>
<th>上任时间</th>
<td><common:canlendarInput empty="true" label="上任时间"
name="ciMgrBasInfoForm" property="cpo.takeDate" size="10"
styleId="takeDate" validator="date(yyyy-mm-dd)"
scope=">=&birth" onchange="checkDate()"
/></td>
<th>本公司工作年限</th>
<td><common:text empty="true" label="本公司工作年限"
name="ciMgrBasInfoForm" property="cpo.hereWorkTime"
validator="integer(0,2)" size="2" styleId="hereWorkTime"
scope="<=&workTime"
/> 年</td>
</tr>
<tr>
<th>从业年数</th>
<td><common:text empty="true" label="从业年数"
name="ciMgrBasInfoForm" property="cpo.workTime"
styleId="workTime" validator="integer(0,2)" size="2"
/> 年</td>
<th>状态</th>
<td><param:select name="ciMgrBasInfoForm" label="状态" empty="false"
type="cmisci.status" property="cpo.status" styleId="status"
nullStr="--请选择--" /></td>
</tr>
<tr>
<th>兼职情况</th>
<td><common:text empty="true" label="兼职情况"
name="ciMgrBasInfoForm" property="cpo.partTimeJob"
styleId="partTimeJob" validator="text(0,30)"
/></td>
<th>是否为个人无限担保责任人</th>
<td><param:select name="ciMgrBasInfoForm" label="状态" empty="true"
type="cmisci.responseFlag" property="cpo.responseFlag" styleId="responseFlag"
nullStr="--请选择--" /></td>
</tr>
<tr>
<th>录入日期 </th>
<td><bean:write name="ciMgrBasInfoForm" property="cpo.inputDate"/></td>
</tr>
<tr>
<th>个人简历</th>
<td colspan="3"><common:textarea empty="true" label="个人简历"
name="ciMgrBasInfoForm" property="cpo.selfInfo"
styleId="selfInfo" validator="text(0,512)" cols="80" rows="4"
style="word-wrap: break-word" /></td>
</tr>
<tr>
<td colspan="4" class="regionfoot">
<input type="button"
name="ciMgrBasInfoForm" value="保 存" onclick="add()"/>
<input type="button" name="ciMgrBasInfoForm" value="返 回"
onclick="forBack()"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</common:form>
</body>
</html:html>