Skip to content

fix(isTaxID): add formatted CPF support and additional test cases for pt-BR locale#2675

Merged
rubiin merged 4 commits intovalidatorjs:masterfrom
easedu:feat/cpf-validation
Mar 4, 2026
Merged

fix(isTaxID): add formatted CPF support and additional test cases for pt-BR locale#2675
rubiin merged 4 commits intovalidatorjs:masterfrom
easedu:feat/cpf-validation

Conversation

@easedu
Copy link
Copy Markdown
Contributor

@easedu easedu commented Mar 3, 2026

Description

This PR extends the existing CPF validation in the pt-BR locale
to also accept formatted CPF input (XXX.XXX.XXX-XX), and adds
comprehensive test cases for both formatted and unformatted CPFs.

Continuation of PR #2644.

Changes

  • Update pt-BR regex to also match formatted CPF (XXX.XXX.XXX-XX)
  • Strip dots and hyphens in ptBrCheck before validation
  • Update introductory comment block to reflect formatting removal
  • Add 12 new test cases (6 valid + 6 invalid) for CPF

Testing

  • ✅ All 306 tests pass
  • ✅ 100% coverage maintained
  • ✅ Existing CNPJ tests unaffected

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Closes #2645

- 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
- Update pt-BR regex to accept formatted CPF (XXX.XXX.XXX-XX)
- Add formatting removal in ptBrCheck before validation
- Reject all-equal-digit CPFs
- Add comprehensive tests for valid and invalid CPFs

Closes validatorjs#2645
@WikiRik
Copy link
Copy Markdown
Member

WikiRik commented Mar 3, 2026

I don't think the title or the description is correct. The only change I see is that we will also accept formatted ones (and adds some additional test cases for CPF). Is that correct? If so; please update the title and the description to reflect that. Also update the introductory text in lines 909-915 of the isTaxID.js file to reflect that we also strip the formatting.

@easedu easedu changed the title feat(isTaxID): add Brazilian CPF validation for pt-BR locale feat(isTaxID): add formatted CPF support and additional test cases for pt-BR locale Mar 3, 2026
@WikiRik WikiRik requested a review from rubiin March 3, 2026 22:30
@WikiRik WikiRik changed the title feat(isTaxID): add formatted CPF support and additional test cases for pt-BR locale fix(isTaxID): add formatted CPF support and additional test cases for pt-BR locale Mar 3, 2026
@easedu
Copy link
Copy Markdown
Contributor Author

easedu commented Mar 3, 2026

Updated! Title, description and the comment block in isTaxID.js now reflect the actual scope of the changes. Thanks for the review.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (90b0a9a) to head (0f6ea41).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2675   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2594      2595    +1     
  Branches       659       659           
=========================================
+ Hits          2594      2595    +1     

☔ 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.

@rubiin rubiin merged commit e8c6914 into validatorjs:master Mar 4, 2026
12 checks passed
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.

feat: add Brazilian CPF validator

3 participants