Inputmask: Standard phone numbers in Brazil

Created on 27 Feb 2015  ·  15Comments  ·  Source: RobinHerbots/Inputmask

Hello Robin,

I saw you implement testing for the phone numbers in Brazil. However, the rule is not exactly the one that tested.

The new Brazilian standard is only applied to mobile phones, which will receive the digit 9 as a prefix.

Then we have the following situations (regex):
Mobile Phones: \([1-9]{2}\) 9[89]\d{3}-\d{4}
Special mobile phones (not receive the extra digit): \([1-9]{2}\) 7\d{3}-\d{4}
Phones "standard": \([1-9]{2}\) [2-6]\d{3}-\d{4}

In fact, we are in transition to a new standard. Many area codes are still with the old standard. We have a transition schedule, if you want to know I can explain.

The EXACT (I Give Up!) rule at this time, is this mask that I created:
http://codepen.io/thiagotalma/pen/MYXvxp

But I have a little problem.
If you use area code where the transition has been made (definition n) the mask works perfectly.

But when we enter a number with the area code according to the definition o mask deteriorates when we enter the 11th digit.

Do you have any idea how to solve this? Or am I doing wrong and has another best way to achieve the same result?

Main Multi & Alternation Phone

Most helpful comment

@thiagotalma Your definition is not actually right.

There were mobile numbers starting with 5, 6, 7, 8 and 9. Line numbers started with 2, 3, 4_, 5_.
So it was like that:

Mobile numbers: (99) (6789){1}999-9999
Line numbers: (99) (2345){1}999-9999

With the new rule, it adds a leading '9' to mobile numbers, exactly so that they can also use the 2345 initiations. Line numbers didn't change. So now the mask can be translated into that:

Mobile numbers with leading nine: (99) [\9]{1}9999-9999
Standard mobile numbers and line numbers: (99) 9999-9999

What we need now is a single mask for both of these.
I'm using this one now:

$("#telefone").inputmask({
    mask: ["(99) 9999-9999", "(99) 99999-9999"]
});

All 15 comments

@thiagotalma ,

It is the alternation which failes. I will have a look at that.

Also, where can I find more information about the Brazil format with area codes etc. I want to use it for the phone alias.

Hello @RobinHerbots
Telephone numbers in Brazil are regulated by a government agency.

The changes were determined by a resolution, which can be accessed here:
http://legislacao.anatel.gov.br/resolucoes/2010/16-resolucao-553

If you have difficulties, I am available to help.

Hugs!

@thiagotalma Your definition is not actually right.

There were mobile numbers starting with 5, 6, 7, 8 and 9. Line numbers started with 2, 3, 4_, 5_.
So it was like that:

Mobile numbers: (99) (6789){1}999-9999
Line numbers: (99) (2345){1}999-9999

With the new rule, it adds a leading '9' to mobile numbers, exactly so that they can also use the 2345 initiations. Line numbers didn't change. So now the mask can be translated into that:

Mobile numbers with leading nine: (99) [\9]{1}9999-9999
Standard mobile numbers and line numbers: (99) 9999-9999

What we need now is a single mask for both of these.
I'm using this one now:

$("#telefone").inputmask({
    mask: ["(99) 9999-9999", "(99) 99999-9999"]
});

@renandecarlo You are wrong.
I posted the official document above. You read?

@thiagotalma Pretty much, where am I wrong?

:clap::clap::clap:
Muito maduro da sua parte.

O documento é claro. Não há o que se discutir.

Seu código no codepen não deixa colocar 2,3,4,5,7 depois do 9, que foi exatamente o propósito de se adicionar o 9 no começo.

Por ex, o celular (21) 97777-1111 falha no seu código. Assim como (21) 7111-1111, que são celulares válidos.

Veja que no documento, ele tem as seguintes especificações:

Celulares
9XXXX XXXX
Ex: 97777-1111, 91111-2222, 95555-3333

XXXX XXXX (first digit 9, 8, 7 or 6)
Ex: 9888-8888, 7222-2222, 6111-1111

7XXX XXXX

Fixos
XXXX XXXX (first digit 2, 3 , 4 or 5)

Nenhum dos exemplos acima funciona no seu mask.

Now that you have read the document and understand the correct pattern we can talk.

My script is not working. And I gave up on making it work. It's getting a monster! When I have free time I work better at it, is currently impossible.

@thiagotalma ,

Wait until the alternations are better worked out.

@RobinHerbots Is there any way to remask the field dynamically? For example, do a .mask on a onKeyDown or onKeyValidation? That would make it possible then.
That would be a "dynamic alternator" or something along these lines.

Yes you can just recall inputmask with a new mask.

Op ma 23 mrt. 2015 om 19:50 schreef renandecarlo [email protected]:

@RobinHerbots https://github.com/RobinHerbots Is there any way to
remask the field dynamically? For example, do a .mask on a onKeyDown or
onKeyValidation? That would make it possible then.


Reply to this email directly or view it on GitHub
https://github.com/RobinHerbots/jquery.inputmask/issues/836#issuecomment-85141852
.

@RobinHerbots is there any way to make the brazilian mask work with regex?

Here is a working regex for all brazilians phones (\+55 [0-9]{2} ((7[0|7|8|9])|([2|3|4|5][0-9])|([7|8|9][0-9]{2}))[0-9]{2}-[0-9]{4})

Including:
0800 999 9999
0300 999 9999
0500 999 9999
0900 999 9999

Remove Phone alias #1981

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webmastervinay picture webmastervinay  ·  4Comments

toxpal picture toxpal  ·  6Comments

richard-flosi picture richard-flosi  ·  3Comments

poornib55 picture poornib55  ·  6Comments

drolsen picture drolsen  ·  3Comments