Is it possible to create a mask for processing non-northern telephone numbers?

For phones from North America (999), 999-9999 works well for the input mask.

However, I cannot find a good example that will handle non-North American numbers. I know that the number of digits can vary, so besides restricting only digits, is there a good example somewhere?

+6
phone-number
source share
6 answers

There really is no common mask: too many combinations.

The only thing that is fixed is the international country code , usually the + prefix.

According to the Wikipedia article on telephone numbering , most countries comply with E.164 numbering.

If I read E.164 correctly, you can safely make the following assumptions:

  • Country Code: 1-3 digits

  • Network and zone code and number: up to 19 digits

I would ask for the country code and have the field "area code + number" in the form of a 19-digit input.

+4
source share

You can display the country code with a simple RegEx, for example:

 ^(?:(?:0(?:0|11)\s?)|+)([17]|2([07]|[1-689]\d)|3([0-469]|[578]\d)|4([013-9]|2\d)|5([1-8]|[09]\d)|6([0-6]|[789]\d)|8([12469]|[03578]\d)|9([0-58]|[679]\d)) 

Further

 (([\s\(\).-]{0,2}\d){4,13})$ 

to extract the national number.

To check the national length and expiration date, you need libphonenumber or the like.

The long RegEx above allows +, 00 or 011 before the country code and the choice of punctuation by the number that will also need to be deleted.

+2
source share

You do not mention your application, but it is certainly possible with regular expressions . You may want to look here .

0
source share

Not easy. Look at this page for an example of why: if you look only at German telephone numbers, you will notice that there are different formats depending on which number you are calling. Which one do you choose? And this is only for German phone numbers; they differ from continent to continent and from country to country.

Going with "only numbers" is probably your safest bet.

0
source share

I would allow spaces, dashes, slashes, and all that, but really only cared for numbers and the optional + sign. Everything else, for example, the adoption of certain blocks of a certain length, simply requires trouble.

0
source share

It may be a bad answer to the old question. But libphonenumber seems like a good solution to your question.

-one
source share

All Articles