close

情況一:長度不合法


情況二:首字不合法


情況三:第二字不合法


情況四:末九碼不合法


情況五:數值檢驗不合法


情況六:合法的身份證號碼


身份證字號判別(完美版)語法:
procedure TForm1.Button1Click(Sender: TObject);
var
  id,idword,first,nineno:string;
  firstno,check,i,j,m,total:integer;
  label aaaaa;
begin
  id:=ansilowercase(edit1.Text);
  idword:='abcdefghjklmnpqrstuvxywzio';
  first:=copy(id,1,1);
  firstno:=pos(first,idword)+9;
  check:=0;
  total:=0;
aaaaa:
    case check of
      0:
        begin
          if length(id)10 then label1.Caption:='錯誤,長度不對!'
          else
            begin
              check:=check+1;
              goto aaaaa;
            end;
        end;                     
      1:                           //首字是否為字母
        begin
          if not (((first>='a')and(first='A')and(first          else
            begin
              check:=check+1;
              goto aaaaa;
            end;
        end;
      2:                           //後九碼是否為數字
        begin
          m:=1;
          for i:=2 to 10 do
            begin
              nineno:=copy(id,i,1);
              if not ((nineno='0')) then
                begin
                  m:=0;
                  break;
                end;
            end;
              if m=0 then label1.Caption:='錯誤,第'+inttostr(i)+' 碼必須是數字啦!'
              else if m=1 then
                begin
                  check:=check+1;
                  goto aaaaa;
                end;
        end;
      3:                           //第二碼是否正確
        begin
          if (strtoint(copy(id,2,1))1) and (strtoint(copy(id,2,1))2) then
            begin
              label1.Caption:='錯誤,第二碼不是1 就是2 ,哪來的'+copy(id,2,1)+' 啊?';
            end
          else
            begin
              check:=check+1;
              goto aaaaa;
            end;
        end;
      4:                           //檢驗值是否正確
        begin
          for j:=2 to 9 do
            total:=total + (strtoint(copy(id,j,1))*(10-j));
          total:=total+strtoint(copy(inttostr(firstno),1,1))+strtoint(copy(inttostr(firstno),2,1))*9
                 +strtoint(copy(id,10,1));
          if (total mod 10) 0 then
            label1.Caption:='錯誤,數值檢驗不合格!'
          else
            label1.Caption:='正確,合格的身份證號碼!';
        end;
    end;
end;


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 arthurliu 的頭像
    arthurliu

    arthurliu's blog

    arthurliu 發表在 痞客邦 留言(0) 人氣()