Remove Country Code from Phone Number

How to remove country code , When Pick Phone Number from contacts

use this function hope it will help you out:

public String phoeNumberWithOutCountryCode(String phoneNumberWithCountryCode) {
Pattern complie = Pattern.compile(" ");
String[] phonenUmber = complie.split(phoneNumberWithCountryCode);
Log.e("number is", phonenUmber[1]);
return phonenUmber[1];
}

Remove country code from phone number?

Use the following regex substitution:

if your format is : +12223334444

$country_code = '+1';
$phone_no = '+12223334444';

echo preg_replace('/^\+?1|\|1|\D/', '', ($phone_no));

Output will : 2223334444

if your format is : 12223334444

$country_code = '1';
$phone_no = '2223334444';

echo preg_replace('/^\+?1|\|1|\D/', '', ($phone_no));

Output will : 2223334444

MySQL: SQL to remove country code from phone number

One way of doing this would be to do a regex replacement:

UPDATE customers
SET phone = REGEXP_REPLACE(phone, '^\\+[0-9]+ ', '');

Demo

If you're using a version of MySQL earlier than 8+, then we can use the base string functions as a workaround:

UPDATE customers
SET phone = SUBSTR(phone, INSTR(phone, ' ') + 1)
WHERE phone LIKE '+%';

Demo

How to remove the country code from the mobile number?

You must know the country to achieve this. Please find my answer, it is helpful to you if you have the countries list. And let me know if you have any issues.

public string RemoveCountryCode()
{
string phonenumber = "+91123123123";

List<string> countries_list = new List<string>();
countries_list.Add("+1");
countries_list.Add("+91");

foreach(var country in countries_list)
{
phonenumber = phonenumber.Replace(country, "");

}

return phonenumber;
}


Related Topics



Leave a reply



Submit