Skip to content

isMobilePhone - incorrect rule for pt-BR locale #1374

Closed
@viniciushvsilva

Description

@viniciushvsilva

Describe the bug
The regexp in use is incorrect for mobile phones in Brazil, and it also has a few bugs as mentioned below:

Bugs

  1. Second regexp group is useless as first group is always used
    The second group ( [6-9]{1}\d{3}\-?\d{4} ) is included in the first one ( \d{4}\-?\d{4} )

  2. There is an OR operator missing between the first and second group

  3. The two digits that precedes the phone number can be wrapped around parentheses, just like the first 3 digits of the en-US phone number, also it's possible to have a space between the country code and area code, and between the area code and phone number

Examples of phone numbers

With country code and area code

  • +55 11 97123-1234
  • +55 11 7123-1234

Without country code, with area code in parentheses

  • (11) 97123-1234
  • (11) 7123-1234

Without country code, with 0 followed by area code

  • 015 97123-1234
  • 015 7123-1234

Without country code, without 0, with area code

  • 11 97123-1234
  • 11 7123-1234

Suggested RegExp
I'd suggest the usage of the following regexp as it fixes above issues.

/^((\+?55\ ?[1-9]{2}\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[6-9]{1}\d{3}\-?\d{4}))$/

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