Skip to content

Commit

Permalink
Merge pull request #43 from chrisgriffith/master
Browse files Browse the repository at this point in the history
Improved US Phone Number formats
  • Loading branch information
yuyang041060120 authored Feb 15, 2017
2 parents 6baf63a + e75fe5e commit d6e8b68
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-validation",
"version": "3.6.0",
"version": "3.6.1",
"description": "angular2 validation",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/custom-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class CustomValidators {
'pt-PT': /^(\+351)?9[1236]\d{7}$/,
'el-GR': /^(\+?30)?(69\d{8})$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
'en-US': /^(\(?[0-9]{3}\)?)((\s|\-){1})?[0-9]{3}((\s|\-){1})?[0-9]{4}$/,
'en-ZM': /^(\+26)?09[567]\d{7}$/,
'ru-RU': /^(\+?7|8)?9\d{9}$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
Expand Down
33 changes: 33 additions & 0 deletions src/specs/custom-validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,37 @@ describe('Custom Validators phone,', () => {
});

});

describe('locale: en-US,', () => {

beforeEach(() => {
validator = CustomValidators.phone("en-US");
});

function phoneDataProvider() {
return [
{phone: '888 555 2112', valid: true},
{phone: '888 555 2112', valid: true},
{phone: '(888) 555-2112', valid: true},
{phone: '(888) 555 2112', valid: true},
{phone: '888-555-2112', valid: true},
{phone: '888-555 2112', valid: true},
{phone: '8885552112', valid: true}
]
}

using(phoneDataProvider, (data) => {
let testCase = data.phone + ' should be ' + (data.valid ? 'valid' : 'invalid');

it(testCase, () => {
control = new FormControl(data.phone);

if (data.valid)
return expect(validator(control)).toBeNull();

expect(validator(control)).toEqual(error);
})
});

});
});

0 comments on commit d6e8b68

Please sign in to comment.