Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a mask to handle non-north american phone numbers?

Tags:

phone-number

For north american phone numbers, (999) 999-9999 works pretty well for an input mask.

However, I can't find a good example that will handle non-north american numbers. I know that the number of digits can vary, so other than restricting it to digits only, is there a good example anywhere?

like image 838
chris Avatar asked Oct 18 '10 18:10

chris


People also ask

How do I make an input mask?

In the Navigation Pane, right-click the object and click Design View on the shortcut menu. Click the field where you want to create the custom input mask. In the Field Properties area, click the Input Mask text box, and then type your custom mask. Press CTRL+S to save your changes.

What data types are supported by input mask?

keyboard is the data type which supported by Input mask.


2 Answers

There is no generic mask, really: There are too many combinations.

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

According to the Wikipedia Article on telephone numbering plans, most countries conform with the E.164 numbering plan.

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

  • Country code: 1-3 digits

  • Network / Area code and Number: Up to 19 digits

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

like image 152
Pekka Avatar answered Oct 16 '22 23:10

Pekka


You can deduce the country code with a simple RegEx such as:

^(?:(?: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))

Followed by

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

to extract the national number.

For validating the national number length and validity, you'd need libphonenumber or similar.

The long RegEx above allows +, 00 or 011 before the country code and a selection of punctuation in the number which will also have to be stripped.

like image 34
g1smd Avatar answered Oct 16 '22 23:10

g1smd