本地化电话号码格式 [英] Localized phone number formatting
问题描述
我查看了 NSFormatter
、NSNumberFormatter
和其他格式化类,但找不到内置解决方案.我需要根据国家代码格式化电话号码.
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.
例如,对于美国,我得到一个字符串,例如 +16313938888
,我需要将其格式化为 +1(631)393-8888
.问题是我需要对所有格式都这样做.荷兰,我收到一个字符串 +31641234567
这将是 +31(6)41 23 45 67
(类似的东西).
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).
200 多个国家/地区的硬编码太乏味了,我真的不知道所有格式规则.我忽略的文档中是否有某些内容,或者是否有人知道管理此内容的开源类?
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?
推荐答案
参见https://github.com/rmaddy/RMPhoneFormat 针对 iOS 特定的解决方案.
See https://github.com/rmaddy/RMPhoneFormat for an iOS specific solution.
这篇关于本地化电话号码格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!