Skip to content

Commit

Permalink
update rules + shouldShowNumberKeyboard logic
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrizmaselli committed Sep 13, 2024
1 parent 1e52af1 commit d2a344c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Logic to validate if a country should use Number Keyboard (shouldShowNumberKeyboard).

## [4.24.7] - 2024-08-30

### Added
Expand Down
9 changes: 6 additions & 3 deletions react/PostalCodeGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ class PostalCodeGetter extends Component {
default:
case POSTAL_CODE: {
const field = getField('postalCode', rules)
const shouldShowNumberKeyboard = !Number.isNaN(
removeNonWords(field.mask)
)
const numericString = field.mask ? removeNonWords(field.mask) : ''
const isPurelyNumeric =
numericString === '' || /^\d+$/.test(numericString)
const shouldShowNumberKeyboard = isNaN(field.mask)
? isPurelyNumeric
: false

return (
<InputFieldContainer
Expand Down
3 changes: 2 additions & 1 deletion react/country/GBR.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default {
maxLength: 50,
fixedLabel: 'Postcode',
required: true,
mask: '',
// UK has different patterns for postal codes alphanumericals, so we need can't use a mask.
mask: NaN,
regex: /^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$/,
postalCodeAPI: false,
size: 'small',
Expand Down
2 changes: 1 addition & 1 deletion react/country/IRL.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
maxLength: 8,
label: 'postalCode',
required: true,
mask: '999 9999',
mask: 'A99 A9A9',
regex: /(?:^[AC-FHKNPRTV-Y][0-9]{2}|D6W)[ -]?[0-9AC-FHKNPRTV-Y]{4}$/,
postalCodeAPI: true,
size: 'small',
Expand Down

0 comments on commit d2a344c

Please sign in to comment.