根据〖中华人民共和国国家标准 GB 11643-1999 〗中有关公民身份号码的规定, 公民身份号码是特征组合码 18 位:由十七位数字本体码和一位数字校验码组成。排列顺序从左至右依次为: 六位数字地址码, 八位数字出生日期码, 三位数字顺序码和一位数字校验码。地址码表示编码对象常住户口所在县(市、旗、区) 的行政区划代码。生日期码表示编码对象出生的年、月、日, 其中年份用四位数字表示,年、月、日之间不用分隔符。顺序码表示同一地址码所标识的区域范围内, 对同年、月、日出生的人员编定的顺序号。顺序码的奇数分给男性,偶数分给女性。 15 位:六位数字地址码,六位数字出生日期码,三位数字顺序码和一位数字校验码。 var codeInfoTst: Tstrings; //总 codeTst: Tstrings; // 代码 InfoTst: Tstrings; // 地址信息 function identityInfo(identitycode: string): string; // 由年月日判断是否为有效日期 function IsDate(Year, Month, Day: string): Boolean; var st: string; begin st := Year + '-'+ Month + '-'+ day; try StrToDate(st); Result := True; except Result := False; end; end; function getdetailedFromCode(code: string): string; // 由身份证的前六位获得省份县市信息 var Index: integer; St: string; begin index := (code); if index = -1 then begin Result := ''; exit; end; st := infoTst[index]; //县 code := copy(code, 1, 4)+ '00'; index := (code); if index = -1 then begin Result := st; exit; end; st := infoTst[index] + st; //市 code := copy(code, 1, 2)+ '0000'; index := (code); if index = -1 then begin Result := st; exit; end; st := infoTst[index] + st; //省 Result := st; end; var YLYear, YLMonth, YlDay, id, sex, code: string; E: integer; St: string; begin e := Length(identitycode); if (e <> 18) or (e <> 15) then result := ''; if (e= 18) then begin YLYear := copy(identitycode, 7, 4); YlMonth := copy(identitycode, 11, 2); YLday := copy(identitycode, 13, 2); id := copy(identitycode, 18,1); end; if (e= 15) then begin YLYear := '19' + copy(identitycode, 7, 2); YlMonth := copy(identitycode, 9, 2); YLday := copy(identitycode, 11, 2); id := copy(identitycode, 15, 1); end; st := ''; if IsDate(YlYear, YlMonth, Ylday) then begin st := YLYear +'年'+ YlMonth +'月'+ YLday +' 日生' end; code := copy(identitycode, 1, 6); st := getdetailedFromCode(code) + ':'+ st; if (StrToInt(id) mod 2= 1) then begin sex :='男'; end else begin sex :='女'; end; st := st+ ':'+ sex +' 性! '+ Trim(IntToStr(e)) +' 位证号! '; Result := st;
一个完整身份证效验程序 来自淘豆网m.daumloan.com转载请标明出处.