From 2c047ee5b5b276d5c89c078e2a7ebfca9db50fd5 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Mon, 9 Dec 2019 13:09:58 +0800 Subject: [PATCH] allow spaces in Hong Kong and Macau phone numbers --- src/lib/isMobilePhone.js | 4 ++-- test/validators.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 38e8adc10..154f6ead3 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -24,8 +24,8 @@ const phones = { 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-GG': /^(\+?44|0)1481\d{6}$/, 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, - 'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/, - 'en-MO': /^(\+?853\-?)?[268]\d{3}\-?\d{4}$/, + 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/, + 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/, 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, 'en-KE': /^(\+?254|0)(7|1)\d{8}$/, diff --git a/test/validators.js b/test/validators.js index f704bb905..5721212d2 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4193,6 +4193,8 @@ describe('Validators', () => { '+85291234567', '+852-91234567', '+852-9123-4567', + '+852 9123 4567', + '9123 4567', '852-91234567', ], invalid: [ @@ -4209,6 +4211,8 @@ describe('Validators', () => { '+85361234567', '+853-61234567', '+853-6123-4567', + '+853 6123 4567', + '6123 4567', '853-61234567', ], invalid: [ @@ -4216,8 +4220,11 @@ describe('Validators', () => { '12345678', '612345678', '+853-12345678', + '+853-22345678', + '+853-82345678', '+853-612345678', '+853-1234-5678', + '+853 1234 5678', '+853-6123-45678', ], },