libPhoneNumber-iOS
libPhoneNumber-iOS copied to clipboard
Formating an international number
I need numbers in international format to be able to call them. So when saving phone numbers I would like to format it in international style, but only if it not already is in international format.
Right now I do this
let numberExample = "491731234567" // German mobile phone number
let phoneNumber = try phoneNumberUtil.parse(numberExample, defaultRegion: "DE")
let result = try phoneNumberUtil.format(phoneNumber, numberFormat: .E164)
What i get is:
+49 4917 31234567
So the problem is that an country code is added - again - no matter if there is one already. Is there any chance to format the number safely, meaning only adding a country code if it is really missing?
I believe this is working as intended, as libPhoneNumber wouldn't consider "49" in "491731234567" to be the country code because the phone number doesn't have the "+" prefix to denote that.