Validação de CPF

Delphi

24/06/2004

Gostaria de saber alguma funçao que verifique a autenticidade do CPF.
Muito Grato,

Paulo :arrow: :)


Maikow

Maikow

Curtidas 0

Respostas

Otto

Otto

24/06/2004

Olá:


function TForm.VerificaCpf(cpf: String): Boolean; 
for valido o resultado é true. 
var   n1, n2, n3, n4, n5, n6, n7, n8, n9, d1, d2 : integer; 
   digitado, calculado : string; 
begin 
             if not(cpf = ´´)then 
                begin 
                     if length(trim(cpf)) <> 11 then 
                        begin 
                             Result := False; 
                        end 
                     else 
                         begin 
                              n1 := StrToInt(cpf[1]); 
                              n2 := StrToInt(cpf[2]); 
                              n3 := StrToInt(cpf[3]); 
                              n4 := StrToInt(cpf[4]); 
                              n5 := StrToInt(cpf[5]); 
                              n6 := StrToInt(cpf[6]); 
                              n7 := StrToInt(cpf[7]); 
                              n8 := StrToInt(cpf[8]); 
                              n9 := StrToInt(cpf[9]); 

                              d1 := n9*2 + n8*3 + n7*4 + n6*5 + n5*6 + n4*7 + n3*8 + n2*9 +n1*10; 
                              d1 := 11 - (d1 mod 11); 
                              if d1 >= 10 then 
                                 d1 := 0; 

                              d2 := d1*2 + n9*3 + n8*4 + n7*5 + n6*6 + n5*7 + n4*8 + n3*9 + n2*10 +n1*11; 
                              d2 := 11 - (d2 mod 11); 
                              if d2 >= 10 then 
                                 d2 := 0; 

                              calculado:=IntToStr(d1)+ IntToStr(d2); 
                              digitado:=cpf[10]+ cpf[11]; 
                              if calculado <> digitado then 
                                 begin 
                                      result := FALSE; 
                                 end 
                              else result := TRUE; 
                         end; 
                end; 

end; 


pra usar:
if VerificarCpf(edit1.text) then
   ShowMessage(´CPF Válido´)
else
   ShowMessage(´CPF inválido´);



T+


GOSTEI 0
Maikow

Maikow

24/06/2004

:lol: Valeu, cara. Há tempos que estava procurando por esta funçao! Brigado!!!


GOSTEI 0
Paulo_amorim

Paulo_amorim

24/06/2004

:lol: Valeu, cara. Há tempos que estava procurando por esta funçao! Brigado!!!


Olá

Essa função está disponível no Site da revista ClubeDelphi...

Na internet se acha em vários locais
até+


GOSTEI 0
POSTAR