From f2381e0fe046a1dc4a6906963425f444bc5ab360 Mon Sep 17 00:00:00 2001 From: Beckett Normington Date: Sun, 31 Oct 2021 01:03:44 -0400 Subject: [PATCH] feat: (isMobilePhone): add Cameroon fr-CM locale (#1772) * Add Cameroon validation regex I have added a regex for validating Cameroonian mobile numbers which should work. I'm not super comfortable with regular expressions, so if I have screwed something up, please let me know. I have done some basic testing and it has functioned fine thus far. * Update README to include fr-CM in isMobilePhone * Add (very) basic testing for Cameroonian mobile number * Fix missing brace (whoops!) * Fix commas (I hope) * Fix sloppy tests Fix my sloppy tests. I'm really tired and probably should not be working on this, but I accidentally added an extra digit while typing. * Update regex for correctness Add mobile prefix (6) to regex, remove space allowance, and optimize regex * Update tests for correctness * Remove invalid space Sorry! * Rerun failed tests (internal server error) --- src/lib/isMobilePhone.js | 1 + test/validators.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index a6a0a85d7..d86712a87 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -76,6 +76,7 @@ const phones = { 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/, 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'fr-CM': /^(\+?237)6[0-9]{8}$/, 'fr-FR': /^(\+?33|0)[67]\d{8}$/, 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, diff --git a/test/validators.js b/test/validators.js index 1b92f3a64..8d566702b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -7568,6 +7568,21 @@ describe('Validators', () => { '088-320000', ], }, + { + locale: 'fr-CM', + valid: [ + '+237677936141', + '237623456789', + '+237698124842', + '237693029202', + ], + invalid: [ + 'NotANumber', + '+(703)-572-2920', + '+237 623 45 67 890', + '+2379981247429', + ], + }, { locale: 'ko-KR', valid: [