Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DigitoVerificadorCNPJ(const CNPJ: string): string;
- const
- Mult : array[1..13] of Byte = (6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2);
- var
- I : Integer;
- Soma1 : Integer;
- Soma2 : Integer;
- Numero : Integer;
- begin
- if Length(CNPJ) <> 12 then
- Exit('');
- Soma1 := 0;
- Soma2 := 0;
- for I := 1 to 12 do
- if TryStrToInt(CNPJ[I], Numero) then
- begin
- Inc(Soma1, Numero * Mult[I+1]);
- Inc(Soma2, Numero * Mult[I]);
- end
- else
- begin
- Exit('');
- //raise Exception.Create('A string informada contem caracteres não numericos');
- end;
- Result := '00';
- Numero := Soma1 mod 11;
- if Numero > 1 then
- begin
- Numero := 11 - Numero;
- Result[1] := IntToStr(Numero)[1];
- Inc(Soma2, Numero * Mult[13]);
- end;
- Numero := Soma2 mod 11;
- if Numero > 1 then
- Result[2] := IntToStr(11 - Numero)[1];
- end;
- function ValidaCNPJ(CNPJ : string): Boolean;
- begin
- if Length(CNPJ) = 14 then
- Result := DigitoVerificadorCNPJ(Copy(CNPJ, 1, 12)) = Copy(CNPJ, 13, 2);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement