Skip to content

feat(mask): implement credit card mask with expiry and CVV#95

Open
mariohmol wants to merge 2 commits intomasterfrom
feat/credit-card-mask
Open

feat(mask): implement credit card mask with expiry and CVV#95
mariohmol wants to merge 2 commits intomasterfrom
feat/credit-card-mask

Conversation

@mariohmol
Copy link
Copy Markdown
Owner

Summary

Closes #12

  • Fixes the broken cartaocredito textMask (had a literal '0' character instead of a space before the expiry section)
  • Implements the full card data mask: number + expiry (MM/YY) + CVV, matching the format the existing validateBr.cartaocredito already expects
  • Detects card type via textMaskFunction on leading digits

Formats

Card type Format
Standard 16-digit (Visa, MC, Discover, JCB) XXXX XXXX XXXX XXXX MM/YY CVV
American Express 15-digit (34xx / 37xx) XXXX XXXXXX XXXXX MM/YY CVVV (4-digit CVV)

Test plan

  • Visa with full number + expiry + CVV
  • Mastercard with full number + expiry + CVV
  • Discover with full number + expiry + CVV
  • JCB with full number + expiry + CVV
  • Amex 37xx prefix → 15-digit format + 4-digit CVV
  • Amex 34xx prefix → 15-digit format + 4-digit CVV
  • Number-only input (partial) does not throw
  • Empty input does not throw
  • All 45 existing mask tests continue to pass

🤖 Generated with Claude Code

mariohmol and others added 2 commits April 15, 2026 02:31
Fixes the broken cartaocredito textMask (had a literal '0' instead of
a space separator) and implements the full card data mask including
expiry date (MM/YY) and CVV, matching the format expected by the
existing validateBr.cartaocredito validator.

- Standard 16-digit cards (Visa, MC, Discover, JCB): XXXX XXXX XXXX XXXX MM/YY CVV
- Amex 15-digit cards (34xx/37xx): XXXX XXXXXX XXXXX MM/YY CVVV (4-digit CVV)
- Uses textMaskFunction to detect card type from leading digits
- Adds 7 unit tests covering all card brands and edge cases

Closes #12

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d field

- fakerBr.cartaocredito() generates a 23-digit string (16-digit card number
  + MMYY expiry + 3-digit CVV) for Visa, Mastercard, and Discover cards;
  output passes validateBr.cartaocredito and maskBr.cartaocredito
- Adds faker tests: digit format check, validateBr round-trip, masked
  output shape check
- Demo: adds credit card field to "Financeiro & Contato" section with live
  masking and validation; fakeCartaoCredito() inline generator drives the
  Gerar Dados button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Credit Card Mask

1 participant