身份證字號驗證+產生器(最終完美版)語法:
(驗證器語法)
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;

(產生器語法)
procedure TForm1.Button2Click(Sender: TObject);
var
  first,char1,s:string;
  firstno,char2,i,k,char10:integer;
  chara:array[3..9]of extended;
  total:extended;
begin
  first:=copy(combobox1.Text,1,2);
  firstno:=strtoint(first)+9;
  char1:=copy(combobox1.Text,10,1);
  if radiobutton1.Checked=true then char2:=1
  else char2:=2;
  total:=0;
  for i:=3 to 9 do
    begin
      chara[i]:=random(10);
      total:=total+chara[i]*(10-i);
    end;
  total:=total+strtofloat(copy(floattostr(firstno),1,1))+strtofloat(copy(floattostr(firstno),2,1))*9
         +char2*8;
         if (strtoint(floattostr(total))mod 10)=0 then char10:=0
         else char10:=10-(strtoint(floattostr(total))mod 10);
  s:='';
  for k:=3 to 9 do
    s:=s+floattostr(chara[k]);
  s:=char1+inttostr(char2)+s+inttostr(char10);
  edit1.Text:=s;
end;


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

    arthurliu's blog

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