tags:

views:

40

answers:

4

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?

A: 

You don't mention your application but this is certainly possible using regular expressions. You might want to take a look here.

m.edmondson
And now, I have two problems :)
chris
+1  A: 

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.

Pekka
A: 

Not easily. Take a look at this page for an example why: if you only look at the German phone numbers, you'll note that there are different formats depending on where you're calling the number from. Which one do you pick? And that's just for German phone numbers; they differ from continent to continent, and from country to country.

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

CanSpice
A: 

I would allow for spaces, dashes, slashes and all that, but actually only care for numbers and the optional leading + sign. Everything else, such as assuming certain blocks of a certain length is just asking for trouble.

Sebastian N.