Remove unwanted characters, country code from phone numbers fetched from contacts iOS [duplicate]

StackOverflow https://stackoverflow.com/questions/22979297

Question

How can i remove unwanted characters, country code from phone numbers fetched from contacts iOS.

Fetch Contacts in iOS 7

I used the above SO link to fetch contacts. Am able to fetch all contacts. But my problem , am getting unwanted character in the phone numbers . How can i remove those unwanted characters from phone numbers in iOS 7 & iOS 6.

Please find contact detail added in Simulator

enter image description here

Please find the log in iOS 7 Simulator below:

2014-04-10 10:43:13.274 AddressBook[946:a0b] Contact name alan bold
2014-04-10 10:43:13.275 AddressBook[946:a0b] Phone number 1 (234) 567-89
2014-04-10 10:43:13.275 AddressBook[946:a0b] All numbers (
    "1\U00a0(234)\U00a0567-89"
)
2014-04-10 10:43:13.276 AddressBook[946:a0b] all contacts (
    "<ContactsData: 0x9984330>"
)

And Please find the log in iOS 6 Simulator below:

2014-04-10 10:37:44.965 AddressBook[883:c07] Fetching contact info ----> 
2014-04-10 10:37:44.973 AddressBook[883:c07] Contact name alsn vols
2014-04-10 10:37:44.974 AddressBook[883:c07] Phone number 1 (234) 567-890
2014-04-10 10:37:44.974 AddressBook[883:c07] All numbers (
    "1 (234) 567-890"
)
2014-04-10 10:37:44.975 AddressBook[883:c07] all contacts (
    "<ContactsData: 0x7c56510>"
)

And guide me how to remove country code from phone numbers

Was it helpful?

Solution

I use Google's libPhoneNumber library to extract the phone number from the contact and normalize it in several formats (Local format, International format and E164 format).

I suggest you to give it a try :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top