Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/lib/isTaxID.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,12 +907,14 @@ function plPlCheck(tin) {
}

/*
* pt-BR validation function
* (Cadastro de Pessoas Físicas (CPF, persons)
* Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
* Both inputs will be validated.
* CNPJ supports both numeric (legacy) and alphanumeric format (starting July 2026).
*/
* pt-BR validation function
* (Cadastro de Pessoas Físicas (CPF, persons)
* Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
* Both inputs will be validated.
* CPF accepts formatted (XXX.XXX.XXX-XX) and unformatted input;
* formatting is stripped before validation.
* CNPJ supports both numeric (legacy) and alphanumeric format (starting July 2026).
*/

/**
* Convert a CNPJ character to its numeric value for check digit calculation.
Expand Down Expand Up @@ -966,6 +968,9 @@ function validateCnpj(cnpj) {
}

function ptBrCheck(tin) {
// Strip CPF formatting (XXX.XXX.XXX-XX)
tin = tin.replace(/[.\-/]/g, '');

if (tin.length === 11) {
let sum;
let remainder;
Expand Down Expand Up @@ -1205,7 +1210,7 @@ const taxIdFormat = {
'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
'nl-NL': /^\d{9}$/,
'pl-PL': /^\d{10,11}$/,
'pt-BR': /(?:^\d{11}$)|(?:^[A-Z0-9]{12}\d{2}$)/i,
'pt-BR': /(?:^\d{3}\.\d{3}\.\d{3}-\d{2}$)|(?:^\d{11}$)|(?:^[A-Z0-9]{12}\d{2}$)/i,
'pt-PT': /^\d{9}$/,
'ro-RO': /^\d{13}$/,
'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
Expand Down
13 changes: 13 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13957,6 +13957,13 @@ describe('Validators', () => {
// CPF (persons)
'35161990910',
'74407265027',
'12345678909',
'11144477735',
'52998224725',
// CPF formatted (XXX.XXX.XXX-XX)
'123.456.789-09',
'111.444.777-35',
'529.982.247-25',
// CNPJ numeric (legacy format)
'05423994000172',
'11867044000130',
Expand All @@ -13967,6 +13974,12 @@ describe('Validators', () => {
invalid: [
'ABCDEFGH',
'170.691.440-72',
'000.000.000-00',
'111.111.111-11',
'123.456.789-00',
'12345678900',
'123',
'123456789012',
'11494282142',
'74405265037',
'11111111111',
Expand Down
Loading