• 身份证验证



    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;

     

  • 相关阅读:
    Dynamics CRM 365 查询安全角色的具体权限明细
    Dynamics CRM 365 JS易错备忘录
    Dynamics CRM 365 9.0版本,在活动增加phonecall和task的时候,在postCreate同步触发的时候拿不到regardingobjectid
    Dynamics 365 通过插件中的retrievemultiple消息来过滤产品视图
    【短视频】达人是什么?
    跨境电商业务知识
    【电商行业】商品标签有哪些?
    二维高斯核函数
    php模拟发送post请求
    scp
  • 原文地址:https://www.cnblogs.com/ryb/p/916460.html
Copyright © 2020-2023  润新知