zoukankan      html  css  js  c++  java
  • 提取身份证信息

    function GetIDInfoGetDInfo(const CardNo: string; var Sex,

      BirthDay: string; var Age: Integer; var Area: string): Integer;

    var

      iCardNo: Int64;

      iYear, iSex: Integer;

      sBirth, fBirth: string;

      dBirth: TDateTime;

    begin

      Result := 0; //表示身份证输入正确

      if (Length(CardNo) <> 15) and (Length(CardNo) <> 18) then

      begin

        Result := 1; //位长不对

        Exit;

      end;

      if Length(CardNo) = 15 then

      begin

        if not TryStrToInt64(CardNo, iCardNo) then

        begin

          Result := 2; //必须为数字

          Exit;

        end;

        sBirth := '19' + Copy(CardNo, 7, 6);

        iSex := StrToInt(Copy(CardNo, 15, 1));

        if Odd(iSex) then

          Sex := '男'

        else

          Sex := '女';

      end

      else

      begin

        if not TryStrToInt64(Copy(CardNo, 1, 17), iCardNo) then

        begin

          Result := 2; //前17位必须为数字

          Exit;

        end;

        sBirth := Copy(CardNo, 7, 8);

        iSex := StrToInt(Copy(CardNo, 17, 1));

        case iSex of

          0: Sex := '未知';

          1: Sex := '男';

          2: Sex := '女';

          9: Sex := '未说明';

        end;

      end;

      fBirth := Format('%s-%s-%s', [Copy(sBirth, 1, 4),

        Copy(sBirth, 5, 2), Copy(sBirth, 7, 2)]);

      if not TryStrToDate(fBirth, dBirth) then

      begin

        Result := 3; //生日格式不对

        Exit;

      end;

      iYear := YearsBetween(Date, dBirth);

      if (iYear < 0) or (iYear >= 120) then

      begin

        Result := 4; //年龄错误

        Exit;

      end;

      BirthDay := sBirth;

      Age := iYear;

      Area := GetArea(StrToInt(Copy(CardNo, 1, 2)));

    end;

  • 相关阅读:
    图论 —— tarjan 缩点 割点 (学习历程)连载中......
    模拟赛记
    模板(按照洛谷顺序)
    CSP-S退役记
    各知识点运用技巧总结
    P3665 [USACO17OPEN]Switch Grass
    跳跳棋——二分+建模LCA
    P3043 [USACO12JAN]牛联盟Bovine Alliance——并查集
    [ZJOI2013]K大数查询——整体二分
    CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths——dsu on tree
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035708.html
Copyright © 2011-2022 走看看