//****************************************************************************// 构造函数,变量为15位或者18位的身份证号码function clsIDCard(CardNo) { this.Valid=false; this.ID15=''; this.ID18=''; this.Local=''; if(CardNo!=null)this.SetCardNo(CardNo);}// 设置身份证号码,15位或者18位clsIDCard.prototype.SetCardNo = function(CardNo) { this.ID15=''; this.ID18=''; this.Local=''; CardNo=CardNo.replace(" ",""); var strCardNo; if(CardNo.length==18) { pattern= /^\d{17}(\d|x|X)$/; if (pattern.exec(CardNo)==null)return; strCardNo=CardNo.toUpperCase(); } else { pattern= /^\d{15}$/; if (pattern.exec(CardNo)==null)return; strCardNo=CardNo.substr(0,6)+'19'+CardNo.substr(6,9) strCardNo+=this.GetVCode(strCardNo); } this.Valid=this.CheckValid(strCardNo);}// 校验身份证有效性clsIDCard.prototype.IsValid = function() { return this.Valid;}// 返回生日字符串,格式如下,1981-10-10clsIDCard.prototype.GetBirthDate = function() { var BirthDate=''; if(this.Valid)BirthDate=this.GetBirthYear()+'-'+this.GetBirthMonth()+'-'+this.GetBirthDay(); return BirthDate;}// 返回生日中的年,格式如下,1981clsIDCard.prototype.GetBirthYear = function() { var BirthYear=''; if(this.Valid)BirthYear=this.ID18.substr(6,4); return BirthYear;}// 返回生日中的月,格式如下,10clsIDCard.prototype.GetBirthMonth = function() { var BirthMonth=''; if(this.Valid)BirthMonth=this.ID18.substr(10,2); if(BirthMonth.charAt(0)=='0')BirthMonth=BirthMonth.charAt(1); return BirthMonth;}// 返回生日中的日,格式如下,10clsIDCard.prototype.GetBirthDay = function() { var BirthDay=''; if(this.Valid)BirthDay=this.ID18.substr(12,2); return BirthDay;}// 返回性别,1:男,0:女clsIDCard.prototype.GetSex = function() { var Sex=''; if(this.Valid)Sex=this.ID18.charAt(16)%2; return Sex;}// 返回15位身份证号码clsIDCard.prototype.Get15 = function() { var ID15=''; if(this.Valid)ID15=this.ID15; return ID15;}// 返回18位身份证号码clsIDCard.prototype.Get18 = function() { var ID18=''; if(this.Valid)ID18=this.ID18; return ID18;}// 返回所在省,例如:上海市、浙江省clsIDCard.prototype.GetLocal = function() { var Local=''; if(this.Valid)Local=this.Local; return Local;}clsIDCard.prototype.GetVCode = function(CardNo17) { var Wi = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); var Ai = new Array('1','0','X','9','8','7','6','5','4','3','2'); var cardNoSum = 0; for (var i=0; i
页面部分**************************************************************身份证验证
本文转载于: