Skip to content

Commit d447b41

Browse files
g1smdjzaefferer
authored andcommitted
Update phonesUK and mobileUK to accept new prefixes. Closes jquery-validationgh-750
1 parent 5cad6b4 commit d447b41

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

additional-methods.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,14 @@ jQuery.validator.addMethod('phoneUK', function(phone_number, element) {
389389
jQuery.validator.addMethod('mobileUK', function(phone_number, element) {
390390
phone_number = phone_number.replace(/\(|\)|\s+|-/g,'');
391391
return this.optional(element) || phone_number.length > 9 &&
392-
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[45789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
392+
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
393393
}, 'Please specify a valid mobile number');
394394

395395
//Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
396396
jQuery.validator.addMethod('phonesUK', function(phone_number, element) {
397397
phone_number = phone_number.replace(/\(|\)|\s+|-/g,'');
398398
return this.optional(element) || phone_number.length > 9 &&
399-
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[45789]\d{8}|624\d{6})))$/);
399+
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/);
400400
}, 'Please specify a valid uk phone number');
401401
// On the above three UK functions, do the following server side processing:
402402
// Compare original input with this RegEx pattern:

test/methods.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,25 +546,54 @@ module("additional methods");
546546

547547
test("phone (us)", function() {
548548
var method = methodTest("phoneUS");
549-
ok( method( "1(212)-999-2345" ), "Valid us phone number" );
550-
ok( method( "212 999 2344" ), "Valid us phone number" );
551-
ok( method( "212-999-0983" ), "Valid us phone number" );
552-
ok(!method( "111-123-5434" ), "Invalid us phone number" );
553-
ok(!method( "212 123 4567" ), "Invalid us phone number" );
549+
ok( method( "1(212)-999-2345" ), "Valid US phone number" );
550+
ok( method( "212 999 2344" ), "Valid US phone number" );
551+
ok( method( "212-999-0983" ), "Valid US phone number" );
552+
ok(!method( "111-123-5434" ), "Invalid US phone number" );
553+
ok(!method( "212 123 4567" ), "Invalid US phone number" );
554554
});
555555

556556
test("phoneUK", function() {
557557
var method = methodTest("phoneUK");
558+
ok( method( "0117 333 5555" ), "Valid UK Phone Number" );
559+
ok( method( "0121 555 5555" ), "Valid UK Phone Number" );
560+
ok( method( "01633 555555" ), "Valid UK Phone Number" );
561+
ok( method( "01298 28555" ), "Valid UK Phone Number" );
562+
ok( method( "015395 55555" ), "Valid UK Phone Number" );
563+
ok( method( "016977 3999" ), "Valid UK Phone Number" );
564+
ok( method( "020 3000 5555" ), "Valid UK Phone Number" );
565+
ok( method( "024 7500 5555" ), "Valid UK Phone Number" );
566+
ok( method( "0333 555 5555" ), "Valid UK Phone Number" );
567+
ok( method( "0500 555555" ), "Valid UK Phone Number" );
568+
ok( method( "055 3555 5555" ), "Valid UK Phone Number" );
569+
ok( method( "07122 555555" ), "Valid UK Phone Number" );
558570
ok( method( "07222 555555" ), "Valid UK Phone Number" );
571+
ok( method( "07322 555555" ), "Valid UK Phone Number" );
572+
ok( method( "0800 555 5555" ), "Valid UK Phone Number" );
573+
ok( method( "0800 355555" ), "Valid UK Phone Number" );
574+
ok( method( "0843 555 5555" ), "Valid UK Phone Number" );
575+
ok( method( "0872 555 5555" ), "Valid UK Phone Number" );
576+
ok( method( "0903 555 5555" ), "Valid UK Phone Number" );
577+
ok( method( "0983 555 5555" ), "Valid UK Phone Number" );
578+
ok( method( "(07122) 555555" ), "Valid UK Phone Number" );
559579
ok( method( "(07222) 555555" ), "Valid UK Phone Number" );
580+
ok( method( "(07322) 555555" ), "Valid UK Phone Number" );
581+
ok( method( "+44 7122 555 555" ), "Valid UK Phone Number" );
560582
ok( method( "+44 7222 555 555" ), "Valid UK Phone Number" );
583+
ok( method( "+44 7322 555 555" ), "Valid UK Phone Number" );
561584
ok(!method( "7222 555555" ), "Invalid UK Phone Number" );
562585
ok(!method( "+44 07222 555555" ), "Invalid UK Phone Number" );
563586
});
564587

565588
test("mobileUK", function() {
566589
var method = methodTest("mobileUK");
590+
ok( method( "07134234323" ), "Valid UK Mobile Number" );
591+
ok( method( "07334234323" ), "Valid UK Mobile Number" );
592+
ok( method( "07624234323" ), "Valid UK Mobile Number" );
567593
ok( method( "07734234323" ), "Valid UK Mobile Number" );
594+
ok( method( "+447134234323" ), "Valid UK Mobile Number" );
595+
ok( method( "+447334234323" ), "Valid UK Mobile Number" );
596+
ok( method( "+447624234323" ), "Valid UK Mobile Number" );
568597
ok( method( "+447734234323" ), "Valid UK Mobile Number" );
569598
ok(!method( "07034234323" ), "Invalid UK Mobile Number" );
570599
ok(!method( "0753423432" ), "Invalid UK Mobile Number" );

0 commit comments

Comments
 (0)