Skip to content

fix(isMobilePhone): fix es-PA regex to validate only Panamanian mobile numbers#2694

Open
Shrawak wants to merge 3 commits intovalidatorjs:masterfrom
Shrawak:fix/isMobilePhone-es-PA-regex
Open

fix(isMobilePhone): fix es-PA regex to validate only Panamanian mobile numbers#2694
Shrawak wants to merge 3 commits intovalidatorjs:masterfrom
Shrawak:fix/isMobilePhone-es-PA-regex

Conversation

@Shrawak
Copy link
Copy Markdown
Contributor

@Shrawak Shrawak commented Mar 31, 2026

Fixes #2433 — Panamanian mobile phone number regex was too permissive.

What changed

The previous regex /^(\+?507)\d{7,8}$/ had three problems:

  1. Accepted any starting digit — Panamanian mobile numbers must start with 6
  2. Wrong length — allowed 7 or 8 digits, mobile numbers are exactly 8 digits after country code
  3. No hyphen support — valid format 6XXX-XXXX was rejected

The new regex /^(\+?507)6\d{3}-?\d{4}$/ enforces:

  • Mobile prefix 6 after country code 507
  • Exactly 8 digits total
  • Optional hyphen (+507 6123-4567 and +50761234567 are both valid)

Before:

'+50712345678' // was valid ❌ (starts with 1, not 6)
'+5073456789'  // was valid ❌ (starts with 3, not 6)

After:

'+50761234567' // valid ✅
'+5076123-4567' // valid ✅
'+50712345678' // invalid ✅

References

References:

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

…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
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9fa1e3a) to head (0419be0).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-PA regex to require mobile prefix 6 and exact digit counts, with optional hyphen.
  • Updated es-PA validator 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rubiin rubiin requested a review from WikiRik March 31, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IsMobilePhone.js - Update Regular Expression for Validating Panamanian Phone Numbers

3 participants