fix(isMobilePhone): fix es-PA regex to validate only Panamanian mobile numbers#2694
fix(isMobilePhone): fix es-PA regex to validate only Panamanian mobile numbers#2694Shrawak wants to merge 3 commits intovalidatorjs:masterfrom
Conversation
…e numbers
The previous regex /^(\+?507)\d{7,8}$/ was too permissive:
- Allowed any starting digit after country code (should be 6 for mobile)
- Accepted 7 or 8 digit lengths (mobile must be exactly 8 digits)
- Did not support hyphenated format (6XXX-XXXX)
The new regex /^(\+?507)6\d{3}-?\d{4}$/ enforces:
- Mobile numbers must start with 6
- Exactly 8 digits after country code
- Optional hyphen in 6XXX-XXXX format
References:
- https://en.wikipedia.org/wiki/Telephone_numbers_in_Panama
- Panamanian mobile numbers: +507 6XXX-XXXX
Fixes validatorjs#2433
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2694 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2595 2595
Branches 659 659
=========================================
Hits 2595 2595 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Updates the es-PA locale in isMobilePhone to properly validate Panamanian mobile numbers only (prefix 6, exact length, optional intra-number hyphen), aligning validation with the intended national format and tightening an overly permissive regex.
Changes:
- Tightened
es-PAregex to require mobile prefix6and exact digit counts, with optional hyphen. - Updated
es-PAvalidator fixtures to reflect the corrected mobile-only behavior and add new invalid cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lib/isMobilePhone.js | Replaces the es-PA regex to enforce Panama mobile number structure (6XXX-XXXX / 6XXXXXXX). |
| test/validators.test.js | Updates es-PA valid/invalid examples to match the new stricter Panama mobile validation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes #2433 — Panamanian mobile phone number regex was too permissive.
What changed
The previous regex
/^(\+?507)\d{7,8}$/had three problems:66XXX-XXXXwas rejectedThe new regex
/^(\+?507)6\d{3}-?\d{4}$/enforces:6after country code507+507 6123-4567and+50761234567are both valid)Before:
After:
References
References:
Checklist