libPhoneNumber-iOS icon indicating copy to clipboard operation
libPhoneNumber-iOS copied to clipboard

Formating an international number

Open beseder42 opened this issue 8 years ago • 1 comments

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?

beseder42 avatar Jan 16 '18 07:01 beseder42

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.

paween avatar Jan 30 '18 18:01 paween