Validar Cnpj
function IsValidCNPJ(CNPJ: string): Boolean;
var
localCGC: string;
digit1, digit2: integer;
ii, soma: integer;
begin
localCGC := ´´;
Result := False;
{analisa CGC no formato 99.999.999/9999-00}
if Length(CNPJ) = 18 then
if (Copy(CNPJ, 3, 1) + Copy(CNPJ, 7, 1) + Copy(CNPJ, 11, 1) + Copy(CNPJ, 16,
1) = ´../-´) then
begin
localCGC := Copy(CNPJ, 1, 2) + Copy(CNPJ, 4, 3) + Copy(CNPJ, 8, 3) +
Copy(CNPJ, 12, 4) + Copy(CNPJ, 17, 2);
Result := True;
end;
{analisa CGC no formato 99999999999900}
if Length(CNPJ) = 14 then
begin
localCGC := CNPJ;
Result := True;
end;
{comeca a verificacao do digito}
if Result then
try
{1° digito}
soma := 0;
for ii := 1 to 12 do
begin
if ii < 5 then
Inc(soma, StrToInt(Copy(localCGC, ii, 1)) * (6 - ii))
else
Inc(soma, StrToInt(Copy(localCGC, ii, 1)) * (14 - ii))
end;
digit1 := 11 - (soma mod 11);
if digit1 > 9 then
digit1 := 0;
{2° digito}
soma := 0;
for ii := 1 to 13 do
begin
if ii < 6 then
Inc(soma, StrToInt(Copy(localCGC, ii, 1)) * (7 - ii))
else
Inc(soma, StrToInt(Copy(localCGC, ii, 1)) * (15 - ii))
end;
digit2 := 11 - (soma mod 11);
if digit2 > 9 then
digit2 := 0;
{Verifica os dois dígitos}
if (Digit1 = StrToInt(Copy(localCGC, 13, 1))) and
(Digit2 = StrToInt(Copy(localCGC, 14, 1))) then
Result := True
else
Result := False;
except
Result := False;
end;
end;
Validar Cpf
function IsValidCPF(CPF: string): Boolean;
var
localCPF: string;
ii, soma: Integer;
digit1, digit2: Integer;
begin
localCPF := ´´;
Result := False;
{analisa CPF no formato 999.999.999-00}
if Length(CPF) = 14 then
if (Copy(CPF, 4, 1) + Copy(CPF, 8, 1) + Copy(CPF, 12, 1) = ´..-´) then
begin
localCPF := Copy(CPF, 1, 3) + Copy(CPF, 5, 3) + Copy(CPF, 9, 3) +
Copy(CPF, 13, 2);
Result := True;
end;
{analisa CPF no formato 99999999900}
if Length(CPF) = 11 then
begin
localCPF := CPF;
Result := True;
end;
{comeca a verificacao do digito}
if Result then
try
{1° digito}
soma := 0;
for ii := 1 to 9 do
Inc(soma, StrToInt(Copy(localCPF, 10 - ii, 1)) * (ii + 1));
digit1 := 11 - (soma mod 11);
if digit1 > 9 then
digit1 := 0;
{2° digito}
soma := 0;
for ii := 1 to 10 do
Inc(soma, StrToInt(Copy(localCPF, 11 - ii, 1)) * (ii + 1));
digit2 := 11 - (soma mod 11);
if digit2 > 9 then
digit2 := 0;
{Verifica os dois dígitos}
if (Digit1 = StrToInt(Copy(localCPF, 10, 1))) and
(Digit2 = StrToInt(Copy(localCPF, 11, 1))) then
Result := True
else
Result := False;
except
Result := False;
end;
end;
Peguei em uma site legal mas esqueci qual era :(
Boa sorte....