本地化的电话号码格式 [英] Localized phone number formatting
问题描述
我查看了 NSFormatter
, NSNumberFormatter
和其他格式化的类,但是找不到建立解决方案。我需要根据国家代码格式化电话号码。例如,对于美国,我得到一个字符串,如 +16313938888
,我需要格式化看起来像 1(631)393-8888
。问题是我需要为所有格式做这个。荷兰,我收到一个字符串 +31641234567
这将是 +31(6)41 23 45 67
)。
<200> 200多个国家的硬编码太乏味了,我真的不知道所有的格式规则。有没有什么在我忽略的文档,或者有人知道一个开源的类来管理这个?
https://github.com/rmaddy/RMPhoneFormat> https://github.com/rmaddy/RMPhoneFormat 为iOS特定解决方案。
I've looked into NSFormatter
, NSNumberFormatter
, and the other formatting classes, but can't find a build into solution. I need to format phone numbers depending on the country code.
For instance, for US, I get a string such as +16313938888
which I need to format to look like +1(631)393-8888
. The problem is I need to do this for all formats. Netherlands, I receive a string +31641234567
which will be +31(6)41 23 45 67
(something like that).
Hardcoding for 200+ countries is too tedious and I really don't know all the format rules. Is there something in the docs I'm overlooking or does anyone know of an open source class that manages this?
See https://github.com/rmaddy/RMPhoneFormat for an iOS specific solution.
这篇关于本地化的电话号码格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!