Skip to content

Commit 519bbc6

Browse files
nschonnijzaefferer
authored andcommitted
phoneUS: Add N11 exclusions. Closes gh-861
Numbers like 911 and 411 cannot be used for area or exchange codes. https://en.wikipedia.org/wiki/NANPA#Numbering_system
1 parent 59bc899 commit 519bbc6

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/additional/phoneUS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
1818
phone_number = phone_number.replace(/\s+/g, "");
1919
return this.optional(element) || phone_number.length > 9 &&
20-
phone_number.match(/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
20+
phone_number.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/);
2121
}, "Please specify a valid phone number");

test/methods.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,11 @@ test("phone (us)", function() {
550550
ok( method( "1(212)-999-2345" ), "Valid US phone number" );
551551
ok( method( "212 999 2344" ), "Valid US phone number" );
552552
ok( method( "212-999-0983" ), "Valid US phone number" );
553-
ok(!method( "111-123-5434" ), "Invalid US phone number" );
554-
ok(!method( "212 123 4567" ), "Invalid US phone number" );
553+
ok(!method( "111-123-5434" ), "Invalid US phone number. Area Code cannot start with 1" );
554+
ok(!method( "212 123 4567" ), "Invalid US phone number. NXX cannot start with 1" );
555+
ok(!method( "234-911-5678" ), "Invalid US phone number, because the exchange code cannot be in the form N11" );
556+
ok(!method( "911-333-5678" ), "Invalid US phone number, because the area code cannot be in the form N11" );
557+
ok(method( "234-912-5678" ), "Valid US phone number" );
555558
});
556559

557560
test("phoneUK", function() {

0 commit comments

Comments
 (0)