显示手机号码的不同方式?
我想让我的用户能够选择他们的电话号码在我的软件中的格式...
在澳大利亚,我通常显示固定电话,例如:
(07) 5588 2299 +61 7 5588 2299(国际)
和移动电话:
0422 444 666 +61 4 22 444 666(国际)
不同国家/地区的电话号码有没有标准格式(如果我弄错了,甚至在澳大利亚也是如此)可以用作模板吗?
提前致谢!
I want to give my users the ability to choose how their phone numbers are formatted 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最初的想法是允许他们指定一个掩码和一个数字,有点像 printf 格式字符串方法。
这样,带有数字
61755882299
的掩码+99 9 999 9999
将格式化为+61 7 558 82299
。但后来我重新考虑:如果您想为用户提供对手机号码进行格式化的能力,只需提供一个免费的文本输入字段即可。
让他们输入任何他们想要的内容。他们可能想输入 1-800-BITE-ME 或任何您想不到的变体:-)
只有当您需要使用代码中的电话号码时,这才会成为问题,即使这样,您可以先删除非数字字符(可能先将字母转换为数字之后)。
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 number61755882299
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).
然而,允许多个国家/地区的电话号码有时可能会含糊不清。
例如,
61755882299
在澳大利亚可以读作+61 7 5588 2299
,在美国读作617-558-8229
(其中额外的9 被忽略;617 是有效的美国区号)。(电话号码中允许包含额外的数字;如果使用字母代替数字,这是一种常见做法;例如:
1-800-MATTRESS
。)在美国,格式为移动电话和固定电话号码没有区别。通常数字用连字符分隔,但也可以用句点和空格分隔,并且区号可以用括号括起来:
示例:
However, allowing phone numbers in multiple countries can be ambiguous sometimes.
For example,
61755882299
can be read as+61 7 5588 2299
in Australia or617-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: