떠돌아 다니는 알고리즘을 델파이로 포팅했음...
 
 
 
 
 
 
주민등록번호 검사 함수 ( '-' 을 제외한 숫자만 남긴 형태로 가공하여 매개변수로 넣어야 함)
  1. function 주민번호체크(const s: String): Boolean; 
  2. const weight='234567892345'
  3. var 
  4. Sum, i: Integer; 
  5. last, lastRes: Integer; 
  6. begin 
  7. Result:=False; 
  8.   
  9. if Length(Trim(s))<>13 then Exit
  10. else begin 
  11. Sum:=0
  12. for i:=1 to 12 do Sum:=Sum+(StrToInt(s[i])*StrToInt(weight[i])); 
  13.   
  14. last:=Sum mod 11
  15. LastRes:=11 - last; 
  16.   
  17. if LastRes=10 then LastRes:=0 
  18. else if LastRes=11 then LastRes:=1
  19.   
  20. if LastRes=StrToInt(s[13]) then Result:=True; 
  21. end
  22. end
 
 
 
 
신용카드번호 검사 함수 ( '-' 을 제외한 숫자만 남긴 형태로 가공하여 매개변수로 넣어야 함)
  1. function 카드번호체크(const s: String): Boolean; 
  2. var 
  3. tmpInt: array [0..15] of Integer; 
  4. i: Integer; 
  5. tmpStr: String
  6. ResultInt, LastInt: Integer; 
  7. begin 
  8. Result:=False; 
  9.   
  10. if Length(Trim(s))<>16 then Exit 
  11. else begin 
  12. for i:=0 to 14 do begin 
  13. if (i mod 2)=0 then begin 
  14. tmpInt[i]:=StrToInt(s[i+1])*2
  15.   
  16. if tmpInt[i]>9 then begin 
  17. tmpStr:=IntToStr(tmpInt[i]); 
  18. tmpInt[i]:=StrToInt(tmpStr[1])+StrToInt(tmpStr[2]); 
  19. end
  20. end 
  21. else tmpInt[i]:=StrToInt(s[i+1]); 
  22. end
  23.   
  24. ResultInt:=0
  25. for i:=0 to 14 do ResultInt:=ResultInt+tmpInt[i]; 
  26.   
  27. tmpStr:=IntToStr(ResultInt); 
  28. LastInt:=10 - StrToInt(tmpStr[Length(tmpStr)]); 
  29.   
  30. if s[16]=IntToStr(LastInt) then Result:=True; 
  31. end
  32. end





 

Posted by bloodguy
,