feat(isMobilePhone): Add Monaco mobile phone numbers support#2697
feat(isMobilePhone): Add Monaco mobile phone numbers support#2697tonienguix wants to merge 2 commits intovalidatorjs:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2697 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2586 2586
Branches 656 656
=========================================
Hits 2586 2586 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ed README and added test
There was a problem hiding this comment.
Pull request overview
Adds a new isMobilePhone locale to support Monaco (fr-MC) phone number validation, including documentation and tests, aligning with the project’s locale-driven regex approach.
Changes:
- Added
fr-MCregex tosrc/lib/isMobilePhone.js. - Added
fr-MCfixtures to theisMobilePhonevalidator test suite. - Documented
fr-MCin the README’sisMobilePhonelocale list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/lib/isMobilePhone.js |
Adds fr-MC locale regex to the phones map. |
test/validators.test.js |
Adds fr-MC valid/invalid fixtures to the isMobilePhone test matrix. |
README.md |
Includes fr-MC in the documented locale list for isMobilePhone. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'fr-FR': /^(\+?33|0)[67]\d{8}$/, | ||
| 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, | ||
| 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, | ||
| 'fr-MC': /^(\+?377)(4[456]\d{6}|6\d{8})$/, |
There was a problem hiding this comment.
The fr-MC pattern mixes different national-number lengths: the 4[456]\d{6} branch matches 8 digits after 377, but the 6\d{8} branch matches 9 digits after 377. This inconsistency is likely unintended and will accept numbers with different lengths depending on prefix. Please verify Monaco’s mobile number length and adjust the regex (and corresponding fixtures) so both branches reflect the correct national significant number length.
| 'fr-MC': /^(\+?377)(4[456]\d{6}|6\d{8})$/, | |
| 'fr-MC': /^(\+?377)(4[456]\d{6}|6\d{7})$/, |
| '+377612345678', | ||
| '+377698765432', | ||
| '37744123456', | ||
| '37745678901', | ||
| '37746234567', | ||
| '377612345678', | ||
| '377698765432', | ||
| ], | ||
| invalid: [ | ||
| '37743123456', | ||
| '+37747123456', | ||
| '+37741123456', | ||
| '+377512345678', |
There was a problem hiding this comment.
The added fr-MC fixtures treat +3776… numbers as having 9 digits after the country code (e.g. +377612345678), while +37744… numbers have 8 digits after the country code. This makes the fixture set internally inconsistent and tightly couples it to the current regex behavior. After confirming the correct Monaco number length, please update these test cases to use the correct digit count consistently.
| '+377612345678', | |
| '+377698765432', | |
| '37744123456', | |
| '37745678901', | |
| '37746234567', | |
| '377612345678', | |
| '377698765432', | |
| ], | |
| invalid: [ | |
| '37743123456', | |
| '+37747123456', | |
| '+37741123456', | |
| '+377512345678', | |
| '+37761234567', | |
| '+37769876543', | |
| '37744123456', | |
| '37745678901', | |
| '37746234567', | |
| '37761234567', | |
| '37769876543', | |
| ], | |
| invalid: [ | |
| '37743123456', | |
| '+37747123456', | |
| '+37741123456', | |
| '+377612345678', |
feat(isMobilePhone): Add Monaco mobile phone numbers support
Added one line of code to provide support for Monaco prefixes:
The regex is based on this reference https://en.wikipedia.org/wiki/Telephone_numbers_in_Monaco
Checklist