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

Improved US Phone Number formats #43

Merged
merged 4 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
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);
})
});

});
});