Skip to content

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

Open
@Nauj-Montes

Description

@Nauj-Montes

Description

The current regular expression used for validating Panamanian phone numbers is flawed and needs updating to accurately match the expected formats for both landline and mobile numbers. The existing regex is as follows:

"es-PA": /^(\+?507)\d{7,8}$/

Problems with the Current Regex

  1. Inaccurate Length Validation: The regex matches 7 or 8 digits after the country code, but does not account for the specific length requirements of Panamanian numbers:

    • Landline Numbers: Should be exactly 7 digits long after the 507 prefix.
    • Mobile Numbers: Should be exactly 8 digits long after the 507 prefix, optionally formatted with a hyphen (e.g., 6XXX-XXXX).
  2. Lack of Prefix Validation: The regex does not enforce valid starting digits:

    • Landline Numbers: Must start with 2.
    • Mobile Numbers: Must start with 6.

    This is a problem because it allows matches such as +50712345678 which shouldn't be valid as shown in the next screenshot.

Description

  1. Missing Hyphen Support: The current regex does not accommodate hyphens in mobile numbers, potentially causing valid numbers like +507 6123-4567 to be incorrectly flagged as invalid as shown in the following screenshot:

Description

Action Required

  • Update the existing regular expression to the recommended solution to ensure accurate validation of Panamanian phone numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions