quinta-feira, 24 de setembro de 2009

Checa cpf

Function ChecaCPF(CPF:String):Boolean;
var
TextCPF:String;
Laco, Soma, Digito1, Digito2:Integer;
begin
Result := False;
for Laco :=1 to Length(CPF) do
if not (CPF[Laco] in ['0'..'9', '-', '.',' ']) then
exit;
TextCPF:= '';
for Laco := 1 to Length(CPF) do
if CPF[Laco] in ['0'..'9'] then
TextCPF := TextCPF + CPF[Laco];
if TextCPF = '' then Result := True;
if Length(TextCPF) <> 11 then Exit;
Soma := 0;
for Laco := 1 to 9 do
Soma := Soma + (StrToInt(TextCPF[Laco])*Laco);
Digito1:= Soma mod 11;
if Digito1 = 10 then Digito1 := 0;
Soma := 0;
For Laco := 1 to 8 do
Soma := Soma + (StrToInt( TextCPF[Laco+1])*(Laco));
Soma := Soma + (Digito1*9);
Digito2 := Soma mod 11;
if Digito2 = 10 then Digito2 := 0;
if Digito1 = StrToInt(TextCPF[10]) then
if Digito2 = StrToInt(TextCPF[11]) then
Result := True;
end;

Nenhum comentário:

Postar um comentário