Como fazer a validação do cpf?
Bom dia a todos!
Preciso saber como faço para validar o cpf digitado pelo usuario?
Desde já agradeço!!!
Connection
Curtidas 0
Respostas
Wilson Junior
24/11/2009
function CPF_Valido(strCPF: string): boolean;
var
sDigInfo, sDigCalc: String[2];
VetCPF: Array[1..11] of ShortInt;
fCPF: Extended;
wCPF_Total: Word;
x: ShortInt;
CodErro: Integer;
begin
Val( strCPF, fCPF, CodErro );
Str( fCPF :11 :0, strCPF );
for x := 1 to 11 do
begin
if Length( Trim(strCPF[x]) ) = 0 then
VetCPF[x] := 0
else
VetCPF[x] := StrToInt( strCPF[x] )
;
end;
sDigInfo := IntToStr( VetCPF[10] ) + IntToStr( VetCPF[11] );
wCPF_Total :=
( VetCPF[1] * 10 ) + ( VetCPF[4] * 7 ) + ( VetCPF[7] * 4 ) +
( VetCPF[2] * 9 ) + ( VetCPF[5] * 6 ) + ( VetCPF[8] * 3 ) +
( VetCPF[3] * 8 ) + ( VetCPF[6] * 5 ) + ( VetCPF[9] * 2 );
wCPF_Total := wCPF_Total - ( wCPF_Total div 11 * 11 );
if wCPF_Total < 2 then
VetCPF[10] := 0
else
VetCPF[10] := 11 - wCPF_Total
;
wCPF_Total :=
( VetCPF[1] * 11 ) + ( VetCPF[4] * 8 ) + ( VetCPF[7] * 5 ) +
( VetCPF[2] * 10 ) + ( VetCPF[5] * 7 ) + ( VetCPF[8] * 4 ) +
( VetCPF[3] * 9 ) + ( VetCPF[6] * 6 ) + ( VetCPF[9] * 3 ) +
( VetCPF[10] * 2 );
wCPF_Total := wCPF_Total - ( wCPF_Total div 11 * 11 );
if wCPF_Total < 2 then
VetCPF[11] := 0
else
VetCPF[11] := 11 - wCPF_Total
;
sDigCalc := IntToStr( VetCPF[10] ) + IntToStr( VetCPF[11] );
Result := sDigCalc = sDigInfo
end;
Espero ter ajudado...!!!
var
sDigInfo, sDigCalc: String[2];
VetCPF: Array[1..11] of ShortInt;
fCPF: Extended;
wCPF_Total: Word;
x: ShortInt;
CodErro: Integer;
begin
Val( strCPF, fCPF, CodErro );
Str( fCPF :11 :0, strCPF );
for x := 1 to 11 do
begin
if Length( Trim(strCPF[x]) ) = 0 then
VetCPF[x] := 0
else
VetCPF[x] := StrToInt( strCPF[x] )
;
end;
sDigInfo := IntToStr( VetCPF[10] ) + IntToStr( VetCPF[11] );
wCPF_Total :=
( VetCPF[1] * 10 ) + ( VetCPF[4] * 7 ) + ( VetCPF[7] * 4 ) +
( VetCPF[2] * 9 ) + ( VetCPF[5] * 6 ) + ( VetCPF[8] * 3 ) +
( VetCPF[3] * 8 ) + ( VetCPF[6] * 5 ) + ( VetCPF[9] * 2 );
wCPF_Total := wCPF_Total - ( wCPF_Total div 11 * 11 );
if wCPF_Total < 2 then
VetCPF[10] := 0
else
VetCPF[10] := 11 - wCPF_Total
;
wCPF_Total :=
( VetCPF[1] * 11 ) + ( VetCPF[4] * 8 ) + ( VetCPF[7] * 5 ) +
( VetCPF[2] * 10 ) + ( VetCPF[5] * 7 ) + ( VetCPF[8] * 4 ) +
( VetCPF[3] * 9 ) + ( VetCPF[6] * 6 ) + ( VetCPF[9] * 3 ) +
( VetCPF[10] * 2 );
wCPF_Total := wCPF_Total - ( wCPF_Total div 11 * 11 );
if wCPF_Total < 2 then
VetCPF[11] := 0
else
VetCPF[11] := 11 - wCPF_Total
;
sDigCalc := IntToStr( VetCPF[10] ) + IntToStr( VetCPF[11] );
Result := sDigCalc = sDigInfo
end;
Espero ter ajudado...!!!
GOSTEI 0
Connection
24/11/2009
Valeu aí ajudou bastante.
OBrigado!!!
GOSTEI 0