떠돌아 다니는 알고리즘을 델파이로 포팅했음...
주민등록번호 검사 함수 ( '-' 을 제외한 숫자만 남긴 형태로 가공하여 매개변수로 넣어야 함)
- function 주민번호체크(const s: String): Boolean;
- const weight='234567892345';
- var
- Sum, i: Integer;
- last, lastRes: Integer;
- begin
- Result:=False;
- if Length(Trim(s))<>13 then Exit
- else begin
- Sum:=0;
- for i:=1 to 12 do Sum:=Sum+(StrToInt(s[i])*StrToInt(weight[i]));
- last:=Sum mod 11;
- LastRes:=11 - last;
- if LastRes=10 then LastRes:=0
- else if LastRes=11 then LastRes:=1;
- if LastRes=StrToInt(s[13]) then Result:=True;
- end;
- end;
신용카드번호 검사 함수 ( '-' 을 제외한 숫자만 남긴 형태로 가공하여 매개변수로 넣어야 함)
- function 카드번호체크(const s: String): Boolean;
- var
- tmpInt: array [0..15] of Integer;
- i: Integer;
- tmpStr: String;
- ResultInt, LastInt: Integer;
- begin
- Result:=False;
- if Length(Trim(s))<>16 then Exit
- else begin
- for i:=0 to 14 do begin
- if (i mod 2)=0 then begin
- tmpInt[i]:=StrToInt(s[i+1])*2;
- if tmpInt[i]>9 then begin
- tmpStr:=IntToStr(tmpInt[i]);
- tmpInt[i]:=StrToInt(tmpStr[1])+StrToInt(tmpStr[2]);
- end;
- end
- else tmpInt[i]:=StrToInt(s[i+1]);
- end;
- ResultInt:=0;
- for i:=0 to 14 do ResultInt:=ResultInt+tmpInt[i];
- tmpStr:=IntToStr(ResultInt);
- LastInt:=10 - StrToInt(tmpStr[Length(tmpStr)]);
- if s[16]=IntToStr(LastInt) then Result:=True;
- end;
- end;
'Delphi' 카테고리의 다른 글
[Delphi] 델파이 OOP의 특성 (0) | 2009.04.18 |
---|---|
[Delphi] Data Types - String (0) | 2009.04.18 |
[Delphi] 어떤 클래스가 어떤 프로퍼티를 가지고 있는지 검사 (0) | 2009.04.18 |
[Delphi] HTTP로 파일 다운로드 (0) | 2009.04.18 |
[Delphi] MD5 함수 (0) | 2009.04.18 |