Skip to content

Instantly share code, notes, and snippets.

@eemr3
Created December 8, 2023 18:43
Show Gist options
  • Select an option

  • Save eemr3/abd6fd908dcd592c66c21844d4043809 to your computer and use it in GitHub Desktop.

Select an option

Save eemr3/abd6fd908dcd592c66c21844d4043809 to your computer and use it in GitHub Desktop.
Vlida CNPJ (JS)
function validaCNPJ (cnpj) {
var b = [ 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 ]
var c = String(cnpj).replace(/[^\d]/g, '')
if(c.length !== 14)
return false
if(/0{14}/.test(c))
return false
for (var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n))
return false
for (var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n))
return false
   return true
}
@eemr3
Copy link
Copy Markdown
Author

eemr3 commented Dec 8, 2023

Tonar publico

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment