validateCnpj function is a utility for validating Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) numbers. It performs comprehensive validation including format checking, length verification, and mathematical validation of the two check digits using the official algorithm.ts
import { validateCnpj } from "@arkyn/server";
rawCnpj (required)XX.XXX.XXX/XXXX-XX) and the raw numeric format (XXXXXXXXXXXXXX).stringbooleantypescript
import { validateCnpj } from "@arkyn/server";// Valid formatted CNPJconst isValid1 = validateCnpj("11.444.777/0001-61");console.log(isValid1);// Output: true// Valid unformatted CNPJconst isValid2 = validateCnpj("11444777000161");console.log(isValid2);// Output: true// Invalid CNPJ (wrong check digits)const isValid3 = validateCnpj("12.345.678/0001-95");console.log(isValid3);// Output: false// Invalid CNPJ (all digits equal)const isValid4 = validateCnpj("11.111.111/1111-11");console.log(isValid4);// Output: false
false if the input is empty or null.false if the raw input length is greater than 18 characters or less than 14 characters.false if the input contains any whitespace characters.false if all 14 digits are identical (e.g., 11111111111111), as these are mathematically valid but not issued.[5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2][6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]removeNonNumeric from @arkyn/shared internally to strip formatting characters before validation.