From d3f5e2dbbb4e090995f1cb01a83db6893ea7cc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Sat, 30 Oct 2021 13:57:49 +0800 Subject: [PATCH] fix(isMobilePhone): use a loose and future-oriented way to verify Chinese mobile phone numbers (#1682) --- src/lib/isMobilePhone.js | 2 +- test/validators.js | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 6ed4e071b..77eee8799 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -116,7 +116,7 @@ const phones = { 'uk-UA': /^(\+?38|8)?0\d{9}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, - 'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[2567]|7[01235678]|9[012356789])[0-9]{8}$/, + 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, }; /* eslint-enable max-len */ diff --git a/test/validators.js b/test/validators.js index 9babc2330..279796869 100644 --- a/test/validators.js +++ b/test/validators.js @@ -6114,19 +6114,28 @@ describe('Validators', () => { { locale: 'zh-CN', valid: [ - '15323456787', '13523333233', - '13898728332', + '13838389438', + '14899230918', + '14999230918', + '15323456787', + '15052052020', + '16237108167', + '008616238234822', + '+8616238234822', + '16565600001', + '17269427292', + '17469427292', + '18199617480', + '19151751717', + '19651751717', '+8613238234822', '+8613487234567', '+8617823492338', '+8617823492338', - '16637108167', '+8616637108167', '+8616637108167', '+8616712341234', - '008618812341234', - '008618812341234', '+8619912341234', '+8619812341234', '+8619712341234', @@ -6135,17 +6144,25 @@ describe('Validators', () => { '+8619312341234', '+8619212341234', '+8619112341234', - '17269427292', - '16565600001', '+8617269427292', + '008618812341234', + '008618812341234', '008617269427292', - '16238234822', - '008616238234822', - '+8616238234822', + // Reserve number segments in the future. + '92138389438', + '+8692138389438', + '008692138389438', + '98199649964', + '+8698099649964', + '008698099649964', ], invalid: [ '12345', '', + '12038389438', + '12838389438', + '013838389438', + '+86-13838389438', '+08613811211114', '+008613811211114', '08613811211114',