Skip to content

Commit

Permalink
Improve zip code masking (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethetter authored Sep 25, 2018
1 parent 0b42cee commit be561cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/components/TextField/Mask.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import React from 'react';
const deliminatedMaskRegex = {
phone: /(\d{3})(\d{1,3})?(\d+)?/,
ssn: /([*\d]{3})([*\d]{1,2})?([*\d]+)?/,
zip: /(\d{5})(\d+)/
zip: /(\d{5})(\d*)/
};

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/components/TextField/Mask.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ describe('Mask', function() {
expect(input.prop('value')).toBe('12345');
});

it('accepts five-digits with bad extra chars', () => {
const data = render({ mask: 'zip' }, { value: '1234-5' });
const input = data.wrapper.find('input');

expect(input.prop('value')).toBe('12345');
});

it('accepts nine-digits with bad extra chars', () => {
const data = render({ mask: 'zip' }, { value: '1234-5-67-89' });
const input = data.wrapper.find('input');

expect(input.prop('value')).toBe('12345-6789');
});

it('accepts nine-digit zip code', () => {
const data = render({ mask: 'zip' }, { value: '123456789' });
const input = data.wrapper.find('input');
Expand Down

0 comments on commit be561cc

Please sign in to comment.