• 身份证验证



    function IDCheck(e: string): Boolean;
    var
      arrVerifyCode, Wi, Checker: TStringList;
      Ai: string;
      strYear, strMonth, strDay, BirthDay: string;
      i, TotalmulAiWi, modValue: Integer;
      strVerifyCode: string;
    begin
      arrVerifyCode := SplitString('1,0,x,9,8,7,6,5,4,3,2', ',');

      Wi := SplitString('7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2', ',');
      Checker := SplitString('1,9,8,7,6,5,4,3,2,1,1', ',');
      if (Length(e) < 15) or (Length(e) = 17) or (Length(e) > 18) then
      begin
        result := False; //IDCheck= "身份证号共有 15 位或16位或18位"
        Exit;
      end;
      if (Length(e) = 16) and ((not IsNumerice(Copy(e, 16, 1))) and (LowerCase(Copy(e, 16, 1)) <> 'x')) then
      begin
        result := False; //IDCheck= "身份证号16位或最后一位为数值或X"
        Exit;
      end;
      if Length(e) = 18 then
      begin
        Ai := Copy(e, 1, 17);
      end
      else
      begin
        Ai := e; //15,16位身份证
        Ai := Copy(Ai, 1, 6) + '19' + Copy(Ai, 7, 9);
      end;
      if not IsNumerice(Ai) then
      begin
        Result := False; //IDCheck= "身份证除最后一位外,必须为数字!"
        Exit;
      end;
      strYear := Copy(Ai, 7, 4);
      strMonth := Copy(Ai, 11, 2);
      strDay := Copy(Ai, 13, 2);
      BirthDay := Trim(strYear) + '-' + Trim(strMonth) + '-' + Trim(strDay);
      if IsDate(BirthDay) then
      begin
    //    ShowMessage(IntToStr( Now - StrToDate(BirthDay)));  1790 2007

        if (StrToInt(Copy(FormatDateTime('YYYY-MM-DD', Now), 1, 4)) - StrToInt(strYear) > 100) or (strtoDateTime(BirthDay) > date) then
        begin
          result := False; //IDCheck= "身份证输入错误!"  352625185012035477
          Exit;
        end;
      end
      else
      begin
        result := False; //IDCheck= "身份证输入错误!"
        Exit;
      end;

      for i := 0 to 16 do
      begin
        TotalmulAiWi := TotalmulAiWi + StrToInt(Copy(Ai, i + 1, 1)) * StrToInt(Wi[i]);
      end;
      modValue := TotalmulAiWi mod 11;
      strVerifyCode := arrVerifyCode[modValue];
      Ai := Ai + strVerifyCode;
      if (Length(e) = 18) and (e <> Ai) then
      begin
        Result := False; //IDCheck= "身份证号码输入错误!"
        Exit;
      end;
      Result := True;
    end;

     

  • 相关阅读:
    2019杭电多校第二场hdu6601 Keen On Everything But Triangle(主席树)
    洛谷P3812 【模板】线性基
    2019牛客多校第二场D-Kth Minimum Clique(优先队列+bitset)
    2019牛客多校第二场H-Second Large Rectangle(单调栈)
    2019杭电多校第一场hdu6581 Vacation(贪心)
    2019牛客多校第二场F-Partition problem(搜索+剪枝)
    2019牛客多校第一场 E-ABBA(dp)
    实验9:Problem H: 薪酬计算
    实验9:Problem G: 克隆人来了!
    实验9:Problem F: 我们来做个Student类吧!
  • 原文地址:https://www.cnblogs.com/ryb/p/916460.html
Copyright © 2020-2023  润新知