NSNumberFormatter to format US Telephone Numbers

后端 未结 5 1432
执念已碎
执念已碎 2020-12-06 12:35

I\'m trying to convert a string of numbers, entered by the user, into a sexy string like Phone.app on the iPhone. Here is the code I\'m using, which doesn\'t work (no specia

5条回答
  •  盖世英雄少女心
    2020-12-06 12:54

    The UIPhoneFormats.plist contains predefined phone formats for each locale. So, if you're only interested in US phone numbers, you'll need to consider these formats:

    +1 (###) ###-####
    1 (###) ###-####
    011 $
    ###-####
    (###) ###-####

    I had to do something similar, and I shared the results I got here: http://the-lost-beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html

提交回复
热议问题