Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

International mobile phone number formatting API?

I have an app that allows users to select a contact - the app then stores the mobile number and compares it to an MessageContact object which is extracted from a Message object (using Message.sender()).

 

The problem being that the MessageContact object's address function retrieves the number, which includes the international dialling codes. (e.g. in my case for the UK, it would show +447xxxxxxxxx)

 

When comparing this to the contact's number from the contact list, the local number is displayed (e.g. in my case for the UK, it would show 07xxxxxxxxx).

 

Obviously I cannot precisely compare +447xxxxxxxxx with 07xxxxxxxxx as they do not match.

 

I suppose I could take off the first few characters and do a contains instead, but this is not clean and the length of the codes change per region.

 

Is there a nicer way to do it? I've had a look around and I haven't found any built in libraries which will convert a local number to an international one.

 

I've also looked at a few KB articles:

 

http://supportforums.blackberry.com/t5/Native-Development/BlackBerry-10-Developer-s-Guide-to-SMS/ta-...

 

But they don't seem to help as they still return the +44.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: International mobile phone number formatting API?

I think you are going to have to clean the number up any way as users can also add all kinds of characters in to a number including spaces, waits, pauses, etc.

 

So for your code to work it will need to strip out all non-numeric values, retaining the plus, any values after or before the number using a # or preceding any characters. Once cleaned yes you will then need to look for a preceding plus and remove the international code.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: International mobile phone number formatting API?

I would also ask myself why am I reinventing the wheel and storing the numbers in a seperate location when the user has already taken the time to enter the number including any neccessary predial codes, pauses, waits, extensions, etc. neccessary for it work in the contacts app?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: International mobile phone number formatting API?

The problem with the contacts app is that it's not necessary to put the predial codes in for local numbers, which means even if I do a direct comparison to the SMS sender and the contact's numbers, they won't match. It would only work if the user entered all their numbers with the predial codes (most of my numbers in my contacts list don't have predial codes - some do - I'm guessing the ones I've added manually are local ones and any that I've added via receiving an SMS probably have the country code prepended).
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: International mobile phone number formatting API?

just a sugestion why not remove the zero from the number then compare if the internatial number contains the number without the leading zero.
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: International mobile phone number formatting API?

Would that work for all number formats globally?
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: International mobile phone number formatting API?

i think yes

this is the number for international format

+6281111111111

local number would be
081111111111

if you remove the 0 from the local number and compare it with international number it will return true cause the international number contain local number (without the 0)

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: International mobile phone number formatting API?

I think no but when your app fails perhaps you will reread my response to understand why.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: International mobile phone number formatting API?

just as a warning: The leading 0 is not a standard, it can be something else. In a corporate context even more so, as external numbers on a telephone system are often prefixed.

I would suggest to look for an existing library, for example
http://code.google.com/p/libphonenumber/
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter