usuário(s) online!

LER DICA
  Artigos Recentes
Todos os Artigos
Mais Votados
Artigos com Arquivos
Por Categoria

  Dicas Recentes
Todas as Dicas
Mais Votadas
Dicas com Arquivos
Por Categoria

  Downloads
Fórum Delphi
E-Zines Anteriores
Notícias
Manifesto Tecnocolor
Nossa Lojinha
Como usar o Site?


  Cadastre-se
Alterar Cadastro
Login/Logout
Escrever Artigos
Escrever Dicas
Meus Artigos
Minhas Dicas


  Contate-nos
Você tem Site?
Indique para Amigos

Validar CNPJ
Validar CNPJ
Delphi 3.x Delphi 4.x Delphi 5.x
Delphi 6.x Delphi 7.x  
Categoria:
Outros
Nível de Habilidade:
Classificação:
Inserção:
17/07/2003
Palavras Principais:
Validar CNPJ
Número de Votos :
4
Usuário: Ramos de Souza Janones
Referência:

Questão/Problema:

Validar CNPJ

Resposta:

function ChkCNPJ(const cCNPJ: string): boolean;
var
i, soma, mult: integer;
CGC: string;
begin
ChkCNPJ := false;
CGC := LimpaString(cCNPJ);
if Length(CGC) <> 14 then exit;
soma := 0; mult := 2;
for i := 12 downto 1 do
begin
soma := soma + CharToInt(CGC[i]) * mult;
mult := mult + 1;
if mult > 9 then mult := 2;
end;
mult := soma mod 11;
if mult <= 1 then mult := 0 else mult := 11 - mult;
if mult <> CharToInt(CGC[13]) then exit;
soma := 0;
mult := 2;
for i := 13 downto 1 do
begin
soma := soma + CharToInt(CGC[i]) * mult;
mult := mult + 1;
if mult > 9 then mult := 2;
end;
mult := soma mod 11;
if mult <= 1 then mult := 0 else mult := 11 - mult;
ChkCNPJ := mult = CharToInt(CGC[14]);
end;


AVALIE ESTA DICA!
Sua Avaliação:
Ruim
Excelente

 2 COMENTÁRIO(S) PARA ESTA DICA
Essa dica é um lixo, uma verdadeira merda. ...
joaquimnabuco
15/04/2005
a função funciona. Embora deve-se obervar a...
reginaldobarcelos
20/04/2005