Skip to content

Conversation

@easedu
Copy link

@easedu easedu commented Dec 21, 2025

Description

This PR implements support for the upcoming alphanumeric CNPJ format (effective July 2026) for Brazilian tax IDs, as described in issue #2639.

Starting July 2026, Brazil's Receita Federal will support alphanumeric CNPJs with the same structure as numeric CNPJs but allowing letters A-Z in addition to digits 0-9.

Changes

  • Update ptBrCheck function in src/lib/isTaxID.js to validate both numeric and alphanumeric CNPJs
  • Add character-to-value conversion (A-Z → 17-42) following the formula: ASCII code - 48
  • Maintain backward compatibility with numeric-only CNPJs
  • Add comprehensive tests for both formats including:
    • Existing numeric CNPJs (backward compatibility)
    • New alphanumeric CNPJs (including official example 12.ABC.345/01DE-35)
    • Invalid CNPJs in both formats
    • Formatted and unformatted inputs

References

The validation algorithm uses:

  • Module 11 check digit calculation
  • Weights from 2 to 9 (right to left, repeating after 8th character)
  • Character conversion: digits 0-9 remain as is, letters A-Z convert to values 17-42
  • Check digit rule: if remainder = 0 or 1 → DV = 0, else → DV = 11 - remainder

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable) - Not applicable: no user-facing documentation changes needed
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Closes #2639

- Update ptBrCheck function to validate both numeric and alphanumeric CNPJs
- Add character-to-value conversion (A-Z → 17-42)
- Maintain backward compatibility with numeric-only CNPJs
- Add comprehensive tests for both formats

Closes validatorjs#2639
@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (784e52a) to head (d109441).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2644   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2572      2574    +2     
  Branches       651       650    -1     
=========================================
+ Hits          2572      2574    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support upcoming alphanumeric CNPJ format (effective July 2026)

1 participant