Skip to content

Commit a902c99

Browse files
authored
MAGETWO-65681: [GitHub][PR] Fix UK mobile number validation #7293
2 parents f1dc91b + 8674155 commit a902c99

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ define([
235235
],
236236
'mobileUK': [
237237
function (value) {
238-
return value.length > 9 && value.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/);
238+
return value.length > 9 && value.match(/^((0|\+44)7\d{3}\s?\d{6})$/);
239239
},
240240
$.mage.__('Please specify a valid mobile number')
241241
],

dev/tests/js/jasmine/tests/lib/mage/validation.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,35 @@ define([
132132
).toEqual(false);
133133
});
134134
});
135+
136+
describe('Testing UK Mobile number validation', function () {
137+
it('Valid UK Mobile Number', function () {
138+
var element = $('<input id="telephone" type="text" value="07400123456" />');
139+
140+
expect($.validator.methods.mobileUK.call(
141+
$.validator.prototype, element.val(), element.get(0)
142+
)).toBeTruthy();
143+
});
144+
it('Invalid UK Mobile Number', function () {
145+
var element = $('<input id="telephone" type="text" value="06400123456" />');
146+
147+
expect($.validator.methods.mobileUK.call(
148+
$.validator.prototype, element.val(), element.get(0)
149+
)).toBeFalsy();
150+
});
151+
it('Valid UK Mobile Number (International)', function () {
152+
var element = $('<input id="telephone" type="text" value="+447400123456" />');
153+
154+
expect($.validator.methods.mobileUK.call(
155+
$.validator.prototype, element.val(), element.get(0)
156+
)).toBeTruthy();
157+
});
158+
it('Invalid UK Mobile Number', function () {
159+
var element = $('<input id="telephone" type="text" value="+446400123456" />');
160+
161+
expect($.validator.methods.mobileUK.call(
162+
$.validator.prototype, element.val(), element.get(0)
163+
)).toBeFalsy();
164+
});
165+
});
135166
});

lib/web/mage/validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
'mobileUK': [
385385
function (phoneNumber, element) {
386386
return this.optional(element) || phoneNumber.length > 9 &&
387-
phoneNumber.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/);
387+
phoneNumber.match(/^((0|\+44)7\d{3}\s?\d{6})$/);
388388
},
389389
$.mage.__('Please specify a valid mobile number')
390390
],

0 commit comments

Comments
 (0)