Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the "+" and country code from a phone number?

I am using following API to get a phone number; however, some of the device will return the number in following format:

"+" + countrycode + phone number Ex. +12062436969

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String phoneNumber = tm.getLine1Number();

I would like to find out a way/algorithm to remove this "+" sign and the country code, so I will get only the last ten digits. Ex. +12062436969 -> 2062436969

I believe I only need the last ten digits. could anyone please suggest any idea?

like image 523
droigons Avatar asked Oct 13 '11 21:10

droigons


People also ask

How do you stop a country code?

You can block these types of calls. In the app tap on the Block List (circle with the line through it along the bottom.) Then tap on the "+" and select "Numbers that begin with." You can then input any area code or prefix you want. You can also block by country code this way.


1 Answers

You should definitely have a look at this amazing library :

http://code.google.com/p/libphonenumber/
https://github.com/googlei18n/libphonenumber

This will solve your problem and might even help you more since you are doing telephony stuff.

like image 183
Savvas Dalkitsis Avatar answered Oct 19 '22 23:10

Savvas Dalkitsis