Fórum Preciso de funções para validar CPF, CNPJ !!!! #190464

23/10/2003

0

respostas no e-mail: aebeloti@click21.com.br
desde já obrigado...


Aebeloti

Aebeloti

Responder

Posts

23/10/2003

Brnz

Ai vão elas...

function TFrmContr.cpf(num:string):Boolean;
var
   n1,n2,n3,n4,n5,n6,n7,n8,n9:Integer;
   d1,d2:Integer;
   Digitado, Calculado:String;
begin
     n1:=StrToInt(num[1]);
     n2:=StrToInt(num[2]);
     n3:=StrToInt(num[3]);
     n4:=StrToInt(num[4]);
     n5:=StrToInt(num[5]);
     n6:=StrToInt(num[6]);
     n7:=StrToInt(num[7]);
     n8:=StrToInt(num[8]);
     n9:=StrToInt(num[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:=num[10]+num[11];
     if Calculado=digitado then
        cpf:=True
     else
         cpf:=False;
end;

function TFrmContr.cnpj(num:string):Boolean;
var
   n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12:Integer;
   d1,d2:Integer;
   Digitado, Calculado:String;
begin
     n1:=StrToInt(num[1]);
     n2:=StrToInt(num[2]);
     n3:=StrToInt(num[3]);
     n4:=StrToInt(num[4]);
     n5:=StrToInt(num[5]);
     n6:=StrToInt(num[6]);
     n7:=StrToInt(num[7]);
     n8:=StrToInt(num[8]);
     n9:=StrToInt(num[9]);
     n10:=StrToInt(num[10]);
     n11:=StrToInt(num[11]);
     n12:=StrToInt(num[12]);
     d1:=n12*2+n11*3+n10*4+n9*5+n8*6+n7*7+n6*8+n5*9+n4*2+n3*3+n2*4+n1*5;
     d1:=11-(d1 mod 11);
     if d1 >= 10 then d1:=0;
        d2:=d1*2+n12*3+n11*4+n10*5+n9*6+n8*7+n7*8+n6*9+n5*2+n4*3+n3*4+n2*5+n1*6;
     d2:=11-(d2 mod 11);
     if d2 >= 10 then d2:=0;
        Calculado:=IntToStr(d1)+IntToStr(d2);
     Digitado:=num[13]+num[14];
     if Calculado=digitado then
        cnpj:=True
     else
         cnpj:=False;
end;


Maiz... Faça o favor de vir até aqui ler...

Sem mais...

BRNz...


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar