Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isMobilePhone - incorrect rule for pt-BR locale #1374

Closed
viniciushvsilva opened this issue Jul 8, 2020 · 8 comments
Closed

isMobilePhone - incorrect rule for pt-BR locale #1374

viniciushvsilva opened this issue Jul 8, 2020 · 8 comments
Labels

Comments

@viniciushvsilva
Copy link
Contributor

viniciushvsilva commented Jul 8, 2020

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}))$/

@profnandaa
Copy link
Member

Thanks for the suggestion, could you open a PR?

@rubiin
Copy link
Member

rubiin commented Jul 15, 2020

if its still available i will be working asap

@viniciushvsilva
Copy link
Contributor Author

#1381

@lacort
Copy link

lacort commented Aug 13, 2020

Hello my friends I'm having trouble sending to cell phones that the second number of cell 4, for example 11945555555, here in São Paulo / Brazil some phones are like this
Suggest :
/(?=^(+?5{2}-?|0)[1-9]{2}-?\d{4}-?\d{4}$)(^(+?5{2}-?|0)[1-9]{2}-?[6-9]{1}\d{3}-?\d{4}$)|(^(+?5{2}-?|0)[1-9]{2}-?9[4-9]{1}\d{3}-?\d{4}$)/

@viniciushvsilva
Copy link
Contributor Author

@lacort Agreed, I was about to publish this but I realised that some numbers in São Paulo might start with 9 and be followed by a 4 (and apparently 3 too), it seems that those are new numbers given by certain ISP companies (like Vivo and Nextel) in São Paulo state (but mainly in São Paulo city). I should have a look at this by the end of the day.

@mikeerickson
Copy link

If anybody wants to tackle this as a PR, I would be most appreciative as it is beyond my immediate knowledge.

@viniciushvsilva
Copy link
Contributor Author

viniciushvsilva commented Aug 14, 2020

#1407

Opened a new PR, with changes I made. It should now support new phone numbers that start with 9 and be followed by 2, 3, 4 and 5 too.

@profnandaa
Copy link
Member

closed in #1407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants