NSNumberFormatter to format US Telephone Numbers

后端 未结 5 1401
执念已碎
执念已碎 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 13:08

    Well a phone number should be 10 characters(11 with the leading 1), so you should start by changing this:

    [formatter setPositiveFormat:@"+# (###) ###-####"];
    

    And speaking of the leading 1, you need to check for that too.

提交回复
热议问题