Fórum Consegui uma função para validar CPF #151451
02/04/2003
0
Ainda não testei.
Function ValidCPF(const s:string): Boolean;
var
i, Numero, Resto : Byte ;
DV1, DV2 : Byte ;
Total, Soma : Integer ;
Begin
result := FALSE;
if length (AllTrim (s)) = 11 Then
begin
Total := 0 ;
Soma := 0 ;
for i := 1 to 9 do
Begin
Try
Numero := StrToInt (s[i]);
Except
Numero := 0;
end;
Total := Total + (Numero * (11 - i)) ;
Soma := Soma + Numero;
end;
Resto := Total mod 11;
if Resto > 1 then
DV1 := 11 - Resto
else
DV1 := 0;
Total := Total + Soma + 2 * DV1;
Resto := Total mod 11;
if Resto > 1 then
DV2 := 11 - Resto
else
DV2 := 0;
if (IntToStr (DV1) = s[10]) and (IntToStr (DV2) = s[11]) then
result := TRUE;
end;
end;
Function ValidCPF(const s:string): Boolean;
var
i, Numero, Resto : Byte ;
DV1, DV2 : Byte ;
Total, Soma : Integer ;
Begin
result := FALSE;
if length (AllTrim (s)) = 11 Then
begin
Total := 0 ;
Soma := 0 ;
for i := 1 to 9 do
Begin
Try
Numero := StrToInt (s[i]);
Except
Numero := 0;
end;
Total := Total + (Numero * (11 - i)) ;
Soma := Soma + Numero;
end;
Resto := Total mod 11;
if Resto > 1 then
DV1 := 11 - Resto
else
DV1 := 0;
Total := Total + Soma + 2 * DV1;
Resto := Total mod 11;
if Resto > 1 then
DV2 := 11 - Resto
else
DV2 := 0;
if (IntToStr (DV1) = s[10]) and (IntToStr (DV2) = s[11]) then
result := TRUE;
end;
end;
Datafron
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)