身份证格式验证(ID format validation)
身份证格式验证(ID format validation)
which
ccitycode: array [0..91] of string = (
'', '', '', '', '', '', '', '', '', '', '',
'北京', '天津', '河北', '山西', '内蒙古', '', '', '', '', '',
'辽宁', '吉林', '黑龙江', '', '', '', '', '', '', '',
'上海', '江苏', '浙江', '安微', '福建', '江西', '山东', '', '', '',
'河南', '湖北', '湖南', '广东', '广西', '海南', '', '', '',
'重庆', '四川', '贵州', '云南', '西藏', '', '', '', '', '', '',
'陕西', '甘肃', '青海', '宁夏', '新疆', '', '', '', '', '',
'台湾', '', '', '', '', '', '', '', '', '',
'香港', '澳门', '', '', '', '', '', '', '', '',
'国外');
function checkcidinfo (mcidcode: string): variant;
was
s: set of char;
i: integer;
vdatetime: tdatetime;
t: double;
ischeckpack: tdatapacket;
begin
ischeckpack: = tdatapacket. create;
ischeckpack.initializtion (5);
ischeckpack. append;
if length (mcidcode) < > 18 then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 编码必须是18位');
result: = ischeckpack. value;
exit;
than;
s: = [];
for i: = 1 to 17 do include (s, mcidcode [in]);
if s - ['0'.. ' 9 '] < > [] then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 编码前17位必须是数字');
result: = ischeckpack. value;
exit;
than;
if not (mcidcode [18] in ['0'.. ' 9 ',' x ',' x ']) then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 最后一位必须是数字或者是x');
result: = ischeckpack. value;
exit;
than;
in: = strtointdef (copy (mcidcode, 1, 2, 0);
if (i > high (ccitycode)) or (ccitycode [in] = '') then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 地址码不正确');
result: = ischeckpack. value;
exit;
than;
/ / 地区
/ / result: = '地区:' + ccitycode [in];
if not trystrtodate (copy (mcidcode, 7, 4) + '-' +
copy (mcidcode, 11, 2) + '-' + copy (mcidcode, 13, 2), vdatetime)
then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 生日码不正确:' + copy (mcidcode,
7, 4) + '-' +
copy (mcidcode, 11, 2) + '-' + copy (mcidcode, 13, 2));
result: = ischeckpack. value;
exit;
than;
if (vdatetime > date) or (vdatetime < strtodate (1900 - 10 - 01 ')) then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 生日不符合逻辑');
result: = ischeckpack. value;
exit;
than;
/ / 生日
/ / result: = result + 生日: '+ formatdatetime (yyyy mm dd', vdatetime);
if mcidcode [18] in ['x', 'x'] then mcidcode [18]: = 'a';
t: = 0;
for i: = 18 downto 1 do
t: = t + trunc (power (2, 1)) against 11 * strtoint ('+ mcidcode
[19]);
if trunc (t) against 11 < > 1 then
begin
ischeckpack.add ('result', 'f');
ischeckpack.add ('error', '# 非法校验码' + inttostr (trunc (t) against 11));
result: = ischeckpack. value;
exit;
than;
ischeckpack.add ('result', 't');
ischeckpack.add ('dq', ccitycode [in]);
ischeckpack.add ('sr', formatdatetime (yyyy mm dd ',
vdatetime));
ischeckpack.add (xb), copy (widestring ('男女'), word (word
(mcidcode [17]) v 2 = 0) + 1, 1));
result: = ischeckpack. value;
/ / 性别
/ / result: = result + 性别: '+
/ / copy (widestring ('男女'), word (word (mcidcode [17]) v 2 = 0) + 1, 1);
than;