JS:證件檢查類

/**
 * 證件操做類
 */

var CertificateUtil =function(){};

/**
 * 驗證各種型證件是否正確
 * @param num 證件號
 * @returns {Boolean} 
 */
CertificateUtil.prototype.cardValidate = function(idobject){
	var num = idobject.num.toUpperCase();
	var type = idobject.idType;
	var nation = idobject.nation;
	var result = false;
	switch (type) {
    case '01':   /**身份證*/
        if(this.idValidate(num)){
        	result = true;
        }
        break;
    case '02':   /**護照*/
        if(/^[a-zA-Z0-9]{8,}$/.test(num)){
        	result = true;
        }
        break;
    case '03':   /**軍官證*/
    	if(!(/^[a-zA-Z0-9\u4e00-\u9fa5\s]{5,18}$/.test(num))){  /**不是這個範圍的字符,返回false;*/
    		return false;
    	}
    	var regexStr = new RegExp("[\u4e00-\u9fa5\u0020]","g");  /**\u4e00-\u9fa5 中文及 \u0020空格*/
    	var regexNum = new RegExp("[a-zA-Z0-9]","g"); /**字母數字*/
    	var matchstr = num.match(regexStr);
    	var matchnum = num.match(regexNum);
    	var length = 0;
    	if( matchstr && matchnum ){
    		length = matchstr.length * 2 + matchnum.length; /***一箇中文按兩個字符計*/
    	}
    	else if(matchstr){
    		length = matchstr.length * 2;
    	}
    	else if(matchnum){
    		length = matchnum.length;
    	}
    	else{
    		length = 0;
    	}
        if(/^[a-zA-Z0-9\u4e00-\u9fa5\s]{5,}$/.test(num) &&  (length <= 18) &&  (length>=10) ){
        	result = true;
        }
        break;
    case '04':   /***港澳回鄉證*/
    	if(nation == 'HKG' && /^[H]\d{8}$/.test(num)){
    		result = true;
    	}
    	if(nation == 'MAC' && /^[M]\d{8}$/.test(num)){
    		result = true;
    	}
        break;
    case '05':   /***其餘*/
    	if(/^[a-zA-Z0-9]{6,}$/.test(num)){
        	result = true;
        }
        break;
    case '06':   /**出生證*/
    	if(/^[a-zA-Z]\d{9}$/.test(num)){
        	result = true;
        }
        break;   
    case '07':   /**戶口本*/
    	if(this.idValidate(num)){
        	result = true;
        }
        break;    
    case '08':   /**士兵證*/
    	if(!(/^[a-zA-Z0-9\u4e00-\u9fa5\s\u0020]{5,18}$/.test(num))){  /**不是這個範圍的字符,返回false;*/
    		return false;
    	}
    	var regexStr = new RegExp("[\u4e00-\u9fa5\u0020]","g");  /***\u4e00-\u9fa5 中文及 \u0020空格*/
    	var regexNum = new RegExp("[a-zA-Z0-9]","g"); /**字母數字*/
    	var matchstr = num.match(regexStr);
    	var matchnum = num.match(regexNum);
    	var length = 0;
    	if( matchstr && matchnum ){
    		length = matchstr.length * 2 + matchnum.length; //一箇中文按兩個字符計
    	}
    	else if(matchstr){
    		length = matchstr.length * 2;
    	}
    	else if(matchnum){
    		length = matchnum.length;
    	}
    	else{
    		length = 0;
    	}
    	if(/^[a-zA-Z0-9\u4e00-\u9fa5\s]{5,}$/.test(num) &&  (length <= 18) &&  (length>=10) ){
        	result = true;
        }
        break;    
    case '09':   /**臺胞證*/
    	if(/^[0-9]{8}$/.test(num)){
        	result = true;
        }
        break;    
    }
    return result;
};



/**
 * 級聯證件類型
 * @param target 目標對象
 * @param isplease 是否顯示請選擇
 * @param that 
 */
CertificateUtil.prototype.cascadeCardType = function(target,isplease,that){
	var appidentifytype = input.appidentifytype;
	var info = "";
	/**中國成年人*/
	var info1="<option value='01'>身份證</option><option value='03'>軍官證</option><option value='08'>士兵證</option>";
	/**中國未成年人*/
	var info5="<option value='01'>身份證</option><option value='06'>出生證</option><option value='07'>戶口本</option>";
	/**中國人,不分紅年與否*/
	var info6="<option value='01'>身份證</option><option value='03'>軍官證</option><option value='06'>出生證</option><option value='07'>戶口本</option><option value='08'>士兵證</option>"
	var info2="<option value='04'>港澳回鄉證</option>";
	var info3="<option value='09'>臺胞證</option>";
	var info4="<option value='02'>護照</option>";
	/**請選擇*/
	var info7="<option value=''>請選擇</option>";
	/**判斷國籍,顯示相應證件類型*/
	var nativacode=$(that).closest(".filltable").find(".nativacode").find("option:selected").val();
	var nativacodeName=$(that).attr("name");
	var isadult="";  /**判斷當前的人是否成年 true 表明未成年  false 表明成年*/
	var insured_isadult = "";  /**被保人是否成年 0表明未成年人 1 表明成年人*/
	var appisadult="";  /**投保人是否成年 0表明未成年人 1 表明成年人*/
	
	if(nativacode==""){
		info = info7;
	}else{
		/**判斷是否成年  1.出生日期 2.isadult*/
		var isadultflag = input.isadult;
		if(isadultflag=="1"){
			if(nativacodeName.indexOf("app")>=0){
				appisadult = "1";
			}
		}
		else if(isadultflag=="0"){
			if(nativacodeName.indexOf("app")>=0){
				appisadult = "1";
			}
			insured_isadult = "0";
		}
		
		/**從出生日期判斷成年與否*/
		var birthvaluestring =$(that).closest(".filltable").find(".birthday").val();  
		var birthvalue="";
		if(birthvaluestring!="" && birthvaluestring!="請選擇"){
			birthvalue= new Date(Date.parse(birthvaluestring.replace(/-/g,"/")));
			isadult = ageUtil.minAgeLimit(birthvalue, 18); /**true 表明未成年  false 表明成年*/
		}else{
			isadult = "";
		}
		
		if(target == null || target ==''){
			return false;
		}
		if(isplease){
			info = "<option value=''>請選擇</option>";
		}
		var value = $(that).val();
		if(value == ''){
			return false;
		}else{
			if(value == 'CHN'){
				if(nativacodeName.indexOf("app")>=0){
					if(appisadult=="1"){
						info += info1;
					}else{
						info += info1;
						if(typeof(isadult) == "boolean"){
							if(isadult){
								 info =info7;
						    	 info += info5;
						    }
						}else{
							info = info7;
					    	info += info6;
						} 
					}
				}
				else if(nativacodeName.indexOf("insured")>=0){
					if(insured_isadult=="0"){
						info += info5;
					}else{
						info += info1;
						if(typeof(isadult) == "boolean"){
							if(isadult){
								 info = info7;
						    	 info += info5;
						    }
						}else{
							info = info7;
					    	info += info6;
						} 
					}
				}
				else if(nativacodeName.indexOf("benef")>=0){
					info += info1;
					if(typeof(isadult) == "boolean"){
						if(isadult){
							info = info7;
					    	 info += info5;
					    }
					}else{
						info = info7;
				    	info += info6;
					} 
				}
			}  /**CHN end*/
			else if(value == 'HKG' || value == 'MAC'){
				info += info2;
			}
			else if(value == 'TWN'){
				info += info3;
			}
			else {
				info += info4;
			}
		}
	}
	if(target != null && target !=""){
			$(target).html(info);
	}
	certificateUtil.isdisplayappidtype();  /**顯示性別,出生日期*/
	certificateUtil.isdisplayappidtypePC();  /**顯示性別,出生日期*/
}



/**
 * 進入頁面時根據國籍,判斷顯示證件
 * */
CertificateUtil.prototype.displayappcardtype=function(){
	/**中國成年人*/
	var info1="<option value=''>請選擇</option><option value='01'>身份證</option><option value='03'>軍官證</option><option value='08'>士兵證</option>";
	/**中國未成年人*/
	var info5="<option value=''>請選擇</option><option value='01'>身份證</option><option value='06'>出生證</option><option value='07'>戶口本</option>";
	/**中國人,不分紅年與否*/
	var info6="<option value=''>請選擇</option><option value='01'>身份證</option><option value='03'>軍官證</option><option value='06'>出生證</option><option value='07'>戶口本</option><option value='08'>士兵證</option>"
	var info2="<option value=''>請選擇</option><option value='04'>港澳回鄉證</option>";
	var info3="<option value=''>請選擇</option><option value='09'>臺胞證</option>";
	var info4="<option value=''>請選擇</option><option value='02'>護照</option>";
	/**請選擇*/
	var info7="<option value=''>請選擇</option>";
	
	/**投保人判斷國籍,不論成年與否若是爲‘請選擇’ ,顯示相應證件類型*/
	var app_nativacode=$("select[name='app_nativacode']").find("option:selected").val();
	var appidentifytype=input.appidentifytype;    /**若是是返回的,則頁面證件類型已經有值*/
	var insured_isadult = "";  /**0表明未成年人進來投保*/
	
	if(app_nativacode==""){  /**國籍默認爲請選擇,值爲空*/
		$('#app_identifytype').html(info7);
	}else{
		/**判斷是否成年  1.isadult 2.出生日期*/
		var isadultflag = input.isadult;
		var isadult="";
		if(isadultflag=="" || typeof(isadultflag) == "undefined" || isadultflag == null){
			var birthvaluestring =$("select[name='app_nativacode']").closest(".app-module-table").find(".birthday").val();  
			var birthvalue="";
			if(birthvaluestring!=""){
				birthvalue= new Date(Date.parse(birthvaluestring.replace(/-/g,"/")));
				isadult = ageUtil.minAgeLimit(birthvalue, 18); /**true 表明未成年  false 表明成年*/
			}else{
				isadult = "";  /**若是成年與否,生日 均爲未知,就會爲空*/
			}
		}else{
			if(isadultflag=="1"){
				isadult = false; /**true 表明未成年  false 表明成年*/
			}else{
				isadult = false; /**true 表明未成年  false 表明成年*/
				insured_isadult = "0"; /**0 表明未成年  1 表明成年*/
			}
		}
		/**根據isadult進行判斷*/
		if(typeof(isadult) == "boolean"){/**成年與否已經知道*/
			if(app_nativacode=='CHN'){
				if(!isadult){  /**成年*/
					$('#app_identifytype').html(info1);
				 }else{  /**未成年*/
					$('#app_identifytype').html(info5);
				 }
			}
		}else{/**成年與否不知道*/
			if(app_nativacode=='CHN'){
				$('#app_identifytype').html(info6);
			}
		}
		if(app_nativacode == 'HKG' || app_nativacode == 'MAC'){
			$('#app_identifytype').html(info2);
		}
		else if(app_nativacode == 'TWN'){
		    $('#app_identifytype').html(info3);
		}
		else if( app_nativacode!='CHN' && app_nativacode!='HKG' && app_nativacode!='MAC' && app_nativacode!='TWN'){
			$('#app_identifytype').html(info4);
		}	
		/**若是國籍不爲空而且證件類型不爲空,表明是返回的*/
		if(app_nativacode!="" && !(appidentifytype=="" || typeof(appidentifytype) == "undefined" || appidentifytype == null)){
			$('#app_identifytype').val(appidentifytype);
		}
	}
	
	/**被保人的國家,決定顯示相應證件類型*/
	$("select[name='insured_nativacode']").each(function(){
		/**var insuredidentifytype=input.insuredidentifytype;    若是是返回的,則頁面證件類型已經有值*/
		var insured_nativacode=$(this).find("option:selected").val();
		if(insured_nativacode==""){  /**國籍默認爲請選擇,值爲空*/
			$(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info7);
			return true; /**跳出當前循環*/
		}
		var insuredidentifytype = $(this).parents(".insured-module-table").find("[name='insured_identifytype']").val();
		if(insuredidentifytype=="" || typeof(insuredidentifytype) == "undefined" || insuredidentifytype == null){
			insuredidentifytype=input.insuredidentifytype;
		}
		var insuredisadultflag = insured_isadult;
		var insureisadult="";
		if(insuredisadultflag=="" || typeof(insuredisadultflag) == "undefined" || insuredisadultflag == null){
			var insuredbirthvaluestring =$(this).closest(".filltable").find(".birthday").val();  
			var insurebirthvalue="";
			if(insuredbirthvaluestring!=""){
				insurebirthvalue= new Date(Date.parse(insuredbirthvaluestring.replace(/-/g,"/")));
				insureisadult = ageUtil.minAgeLimit(insurebirthvalue, 18); /**true 表明未成年  false 表明成年*/
			}else{
				insureisadult = "";  /**若是成年與否,生日 均爲未知,就會爲空*/
			}
		}else{
			if(insuredisadultflag=="0"){
				insureisadult = true; /**true 表明未成年  false 表明成年*/
			}else{
				insureisadult = false; /**true 表明未成年  false 表明成年*/
			}
		}
		
		/**根據insureisadult進行判斷*/
		if(typeof(insureisadult) == "boolean"){/**成年與否已經知道*/
			if(insured_nativacode=='CHN'){
				if(!insureisadult){  /**成年*/
					$(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info1);
				 }else{  /**未成年*/
					 $(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info5);
				 }
			}
		}else{/**成年與否不知道*/
			if(insured_nativacode=='CHN'){
				$(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info6);
			}
		}
	    if(insured_nativacode == 'HKG' || insured_nativacode == 'MAC'){
			$(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info2);
		}
		else if(insured_nativacode == 'TWN'){
			$(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info3);
		}
		else if( insured_nativacode!='CHN' && insured_nativacode!='HKG' && insured_nativacode!='MAC' && insured_nativacode!='TWN'){
			$(this).parents(".insured-module-table").find("[name='insured_identifytype']").html(info4);
		}
		/**若是國籍不爲空而且證件類型不爲空,表明是返回的*/
		if(insured_nativacode!="" && !(insuredidentifytype=="" || typeof(insuredidentifytype) == "undefined" || insuredidentifytype == null)){
			$(this).parents(".insured-module-table").find("[name='insured_identifytype']").val(insuredidentifytype);
		}
	});

	/**受益人判斷是中國,顯示相應證件類型*/
	$("select[name='benef_nativacode']").each(function(){
		var benef_nativacode=$(this).find("option:selected").val();
		if(benef_nativacode==""){  /**國籍默認爲請選擇,值爲空*/
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info7);
			return true; /**跳出當前循環*/
		}
		var benefisadult="";
		var benefbirthvaluestring =$(this).closest(".filltable").find(".birthday").val();  
		var benefbirthvalue="";
		if(benefbirthvaluestring!=""){
			benefbirthvalue= new Date(Date.parse(benefbirthvaluestring.replace(/-/g,"/")));
			benefisadult = ageUtil.minAgeLimit(benefbirthvalue, 18); /**true 表明未成年  false 表明成年*/
		}else{
			benefisadult = "";  /**若是成年與否,生日 均爲未知,就會爲空*/
		}
		
		/**var benidtype = $(this).parents(".benef-module-table").find("[name='benef_benidtype'] option:selected").text();*/
		var benidtype = $(this).parents(".benef-module-table").find("[name='benef_benidtype']").val();
		
		if(typeof(benefisadult) == "boolean"){/**成年與否已經知道*/
			if(benef_nativacode=='CHN'){
				if(!benefisadult){  /**成年*/
					$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info1);
				 }else{  /**未成年*/
					 $(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info5);
				 }
			}
		}else{/**成年與否不知道*/
			if(benef_nativacode=='CHN'){
				$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info6);
			}
		}
		if(benef_nativacode == 'HKG' || benef_nativacode == 'MAC'){
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info2);
		}
		else if(benef_nativacode == 'TWN'){
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info3);
		}
		else if( benef_nativacode!='CHN' && benef_nativacode!='HKG' && benef_nativacode!='MAC' && benef_nativacode!='TWN'){
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info4);
		}
		/**若是國籍不爲空而且證件類型不爲空,表明是返回的*/
		if(benef_nativacode!="" && !(benidtype=="" || typeof(benidtype) == "undefined" || benidtype == null)){
			var value = 'option[value=\"'+benidtype+'\"]';
			$(this).parents('.benef-module-table').find("[name='benef_benidtype']").find(value).attr("selected",true);
		}
	});
	certificateUtil.isdisplayappidtype();  /**顯示性別,出生日期*/
	certificateUtil.isdisplayappidtypePC();  /**顯示性別,出生日期*/
};

CertificateUtil.prototype.benefbenidtype=function(){
	/**受益人判斷是中國,顯示相應證件類型*/
	$("select[name='benef_nativacode']").each(function(){
		var benef_nativacode=$(this).find("option:selected").val();
		if(benef_nativacode==""){  /**國籍默認爲請選擇,值爲空*/
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info7);
			return true; /**跳出當前循環*/
		}
		var benefisadult="";
		var benefbirthvaluestring =$(this).closest(".filltable").find(".birthday").val();  
		var benefbirthvalue="";
		if(benefbirthvaluestring!=""){
			benefbirthvalue= new Date(Date.parse(benefbirthvaluestring.replace(/-/g,"/")));
			benefisadult = ageUtil.minAgeLimit(benefbirthvalue, 18); /**true 表明未成年  false 表明成年*/
		}else{
			benefisadult = "";  /**若是成年與否,生日 均爲未知,就會爲空*/
		}
		var benidtype = $(this).parents(".benef-module-table").find("[name='benef_benidtype']").val();
		if(typeof(benefisadult) == "boolean"){/**成年與否已經知道*/
			if(benef_nativacode=='CHN'){
				if(!benefisadult){  /**成年*/
					$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info1);
				 }else{  /**未成年*/
					 $(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info5);
				 }
			}
		}else{/**成年與否不知道*/
			if(benef_nativacode=='CHN'){
				$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info6);
			}
		}
		if(benef_nativacode == 'HKG' || benef_nativacode == 'MAC'){
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info2);
		}
		else if(benef_nativacode == 'TWN'){
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info3);
		}
		else if( benef_nativacode!='CHN' && benef_nativacode!='HKG' && benef_nativacode!='MAC' && benef_nativacode!='TWN'){
			$(this).parents(".benef-module-table").find("[name='benef_benidtype']").html(info4);
		}
		/**若是國籍不爲空而且證件類型不爲空,表明是返回的*/
		if(benef_nativacode!="" && !(benidtype=="" || typeof(benidtype) == "undefined" || benidtype == null)){
			var value = 'option[value=\"'+benidtype+'\"]';
			$(this).parents('.benef-module-table').find("[name='benef_benidtype']").find(value).attr("selected",true);
		}
	});
	certificateUtil.isdisplayappidtype();  /**顯示性別,出生日期*/
	certificateUtil.isdisplayappidtypePC();  /**顯示性別,出生日期*/
}


CertificateUtil.prototype.enableSex=function(){
	var app_nativacode=$("select[name='app_nativacode']").find("option:selected").val();
	if(app_nativacode!='CHN'){
		$("input[name='app_sex']").removeAttr("disabled");
	}	
}


/**
 * 根據證件類型,判斷是否顯示性別
 * */
CertificateUtil.prototype.isdisplayappidtype=function(){
	var idtypes = $(".idType");
	for(var i = 0; i < idtypes.length; i++){
		var idtype = $(idtypes[i]).val();
		if(idtype=='01'){
			$(idtypes[i]).closest("ul").find(".displayappsex").attr("style","display:none");
			$(idtypes[i]).closest("ul").find(".displayappbirday").attr("style","display:none");
			$(idtypes[i]).closest("ul").find(".displayinsuresex").attr("style","display:none");
			$(idtypes[i]).closest("ul").find(".displayinsurebirday").attr("style","display:none");
		}else{	
			$(idtypes[i]).closest("ul").find(".displayappsex").attr("style","");
			$(idtypes[i]).closest("ul").find(".displayappbirday").attr("style","");
			$(idtypes[i]).closest("ul").find(".displayinsuresex").attr("style","");
			$(idtypes[i]).closest("ul").find(".displayinsurebirday").attr("style","");
		}
	}

};


/**
 * 根據證件類型,判斷是否顯示性別,PC端
 * */
CertificateUtil.prototype.isdisplayappidtypePC=function(){
	var idtypes = $(".idType");
	for(var i = 0; i < idtypes.length; i++){
		var idtype = $(idtypes[i]).val();
		if(idtype=='01'){
			$(idtypes[i]).parents("table").find("#displayappsex").attr("style","display:none");
			$(idtypes[i]).parents("table").find("#displayappbirday").attr("style","display:none");
			$(idtypes[i]).parents("table").find("#displayinsuresex").attr("style","display:none");
			$(idtypes[i]).parents("table").find("#displayinsurebirday").attr("style","display:none");
		}else{	
			$(idtypes[i]).parents("table").find("#displayappsex").attr("style","");
			$(idtypes[i]).parents("table").find("#displayappbirday").attr("style","");
			$(idtypes[i]).parents("table").find("#displayinsuresex").attr("style","");
			$(idtypes[i]).parents("table").find("#displayinsurebirday").attr("style","");
		}
	}
	certificateUtil.enableSex();
};


/**
 * 驗證身份證是否正確
 * @param num 身份證
 * @returns {Boolean}
 */
CertificateUtil.prototype.idValidate = function(num) {
    num = num.toUpperCase();
    /**身份證號碼爲15位或者18位,15位時全爲數字,18位前17位爲數字,最後一位是校驗位,可能爲數字或字符X。  */
    if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
        /**alert('輸入的身份證號長度不對,或者號碼不符合規定!\n15位號碼應全爲數字,18位號碼末位能夠爲數字或X。');*/
        return false;
    }
    /**校驗位按照ISO 7064:1983.MOD 11-2的規定生成,X能夠認爲是數字10。*/
    /**下面分別分析出生日期和校驗位*/
    var len, re;
    len = num.length;
    if (len == 15) {
        re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
        var arrSplit = num.match(re);

        /**檢查生日日期是否正確*/
        var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay) {
            /**alert('輸入的身份證號裏出生日期不對!');*/
            return false;
        }
        else {
            /**將15位身份證轉成18位*/
            /**校驗位按照ISO 7064:1983.MOD 11-2的規定生成,X能夠認爲是數字10。*/
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
            for (i = 0; i < 17; i++) {
                nTemp += num.substr(i, 1) * arrInt[i];
            }
            num += arrCh[nTemp % 11];
            return true;
        }
    }
    if (len == 18) {
        re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
        var arrSplit = num.match(re);

        /**檢查生日日期是否正確*/
        var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay) {
            /**alert(dtmBirth.getYear());*/
            /**alert(arrSplit[2]);*/
            /**alert('輸入的身份證號裏出生日期不對!');*/
            return false;
        }
        else {
            /**檢驗18位身份證的校驗碼是否正確。*/
            /**校驗位按照ISO 7064:1983.MOD 11-2的規定生成,X能夠認爲是數字10。*/
            var valnum;
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            for (i = 0; i < 17; i++) {
                nTemp += num.substr(i, 1) * arrInt[i];
            }
            valnum = arrCh[nTemp % 11];
            if (valnum != num.substr(17, 1)) {
                /**alert('18位身份證的校驗碼不正確!'); //應該爲: + valnum*/
                return false;
            }
            return true;
        }
    }
    return false;
};

var certificateUtil=new CertificateUtil();
相關文章
相關標籤/搜索