Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve brazilian postcode validation #2211

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions .changeset/rare-dodos-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@adyen/adyen-web': patch
---

Better regex & error message for validation/formatting of Brazilian post codes.
We now allow a hyphen between the 5th & 6th digits
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ export const countrySpecificFormatters: CountryFormatRules = {
postalCode: createFormatByDigits(4)
},
BR: {
postalCode: createFormatByDigits(8)
postalCode: {
// Formatter - excludes non digits, but allows hyphens, and limits to a maxlength that varies depending on whether a hyphen is present or not
formatterFn: val => {
const nuVal = val.replace(getFormattingRegEx('^\\d-', 'g'), '');
const maxlength = nuVal.indexOf('-') > -1 ? 9 : 8;
return nuVal.substr(0, maxlength);
sponglord marked this conversation as resolved.
Show resolved Hide resolved
},
format: '12345678 or 12345-678',
maxlength: 9
}
},
CA: {
postalCode: {
Expand Down Expand Up @@ -181,7 +190,7 @@ export const countrySpecificFormatters: CountryFormatRules = {
},
PL: {
postalCode: {
// Formatter - excludes non digits & hyphens and limits to a maxlength that varies depending on whether a hyphen is present or not
// Formatter - excludes non digits, but allows hyphens, and limits to a maxlength that varies depending on whether a hyphen is present or not
formatterFn: val => {
const nuVal = val.replace(getFormattingRegEx('^\\d-', 'g'), '');
const maxlength = nuVal.indexOf('-') > -1 ? 6 : 5;
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/internal/Address/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const postalCodePatterns = {
AU: createPatternByDigits(4),
BE: { pattern: /(?:(?:[1-9])(?:\d{3}))/ },
BG: createPatternByDigits(4),
BR: createPatternByDigits(8),
BR: { pattern: /^\d{5}-?\d{3}$/ },
CA: { pattern: /(?:[ABCEGHJ-NPRSTVXY]\d[A-Z][ -]?\d[A-Z]\d)/ },
CH: { pattern: /[1-9]\d{3}/ },
CY: createPatternByDigits(4),
Expand Down