0

I'm trying to find a way to use NSNumberFormatter to format an input string of digits into a US phone number style.

For example: 4155552671 should be +1-415-555-2671 (if i'm not mistaken)

I was wondering if theres an easy way to do this with native API (NSNumberFormatterStyle?), instead of using my own logic to modify the string. any thoughts? Thanks.

Lirik
  • 3,167
  • 1
  • 30
  • 31
  • 1
    `NSNumberFormatter` is not appropriate in any way for formatting phone numbers. Remember, a phone number isn't actually a number (in a math/computer sense). No numeric data type should ever be used to store a phone number. – rmaddy Apr 11 '16 at 20:22

1 Answers1

1

This is not a suitable task for NSNumberFormatter.

Maybe this answer can help.

There's also an iOS ported version of Google's phone number library which might help, you're probably looking for the RFC3966 output or a variation of the international one.

Community
  • 1
  • 1
Stavash
  • 14,244
  • 5
  • 52
  • 80