开发者

Different ways to display mobile phone numbers?

开发者 https://www.devze.com 2023-04-01 10:49 出处:网络
I want to give my users the ability to choose how their phone numbers are form开发者_JAVA技巧atted within my software...

I want to give my users the ability to choose how their phone numbers are form开发者_JAVA技巧atted within my software...

Here in Australia I normally display landline phones like:

(07) 5588 2299 +61 7 5588 2299 (international)

And mobile (cell) phones like:

0422 444 666 +61 4 22 444 666 (international)

Is there any standard format for phone numbers in different countries (and even here in Australia if I have it wrong) that I could use as a template?

Thanks in advance!


My original thought was to allow them to specify a mask and a number, sort of like a printf format string method.

That way the mask +99 9 999 9999 with the number 61755882299 would format as +61 7 558 82299.

But then I reconsidered: if you want to give users formatting ability over their mobile phone numbers, just provide a free text entry field.

Let them enter whatever they want. They may want to enter 1-800-BITE-ME or any number of variations you won't have thought of :-)

That will only ever become a problem if you need to use the phone numbers from within your code and, even then, you could just strip out the non-digit characters first (after possibly converting letters to digits first).


However, allowing phone numbers in multiple countries can be ambiguous sometimes.

For example, 61755882299 can be read as +61 7 5588 2299 in Australia or 617-558-8229 in the United States (where the extra 9 is disregarded; 617 is a valid U.S. area code).

(It is allowable to have extra numbers in a phone number; this is a common practice if letters are used instead of numbers; for example: 1-800-MATTRESS.)

In the U.S., the formatting of mobile and landline phone numbers does not differ. Usually numbers are separated by hyphens, but they can also be separated by periods and spaces, and the area code can be enclosed in parentheses:

Examples:

888-555-1234
888.555.1234
888 555-1234
(888) 555-1234
0

精彩评论

暂无评论...
验证码 换一张
取 消