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;

  • 相关阅读:
    LeetCode-018-四数之和
    LeetCode-017-电话号码的字母组合
    LeetCode-016-最接近的三数之和
    LeetCode-015-三数之和
    LeetCode-014-最长公共前缀
    LeetCode-013-罗马数字转整数
    LeetCode-012-整数转罗马数字
    LeetCode-011-盛最多水的容器
    LeetCode-010-正则表达式匹配
    [leetcode]103. Binary Tree Zigzag Level Order Traversal二叉树Z形遍历
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035708.html
Copyright © 2011-2022 走看看