Remove area code from Telephonenumber

How to remove coutrycode from telphonumber.

number may come in this format.

4770300000
004770300000
+4770300000
4670300000

I would like to remove the country codes so that they are matched against the number against.

070300000
+3
source share
4 answers

The following should replace any valid country code (starting with "00" or "+") with a leading zero.

resultString = Regex.Replace(subjectString, @"^(00|\+)(1|2[078]|2[1234569][0-9]|3[0123469]|3[578][0-9]|4[013456789]|42[0-9]|5[09][0-9]|5[12345678]|6[0123456]|6[789][0-9]|7|8[0578][0-9]|8[123469]|9[0123458]|9[679][0-9])", "0");
+2
source

It's complicated. Both country codes and national numbers vary in length. In addition, there are regional codes that some countries use and some do not. And then there are optional leading "+" or "00". Not to mention the number of emergency services.

; ! - . .

. , :

PhoneNumberUtil.GetInstance().Parse(phoneno, "").NationalNumber
+1

? (, 47 46):

resultString = Regex.Replace(subjectString, @"(\+|\b00|\b)4[67]", "0");

4770300000 004770300000 +4770300000 4670300000

070300000 070300000 070300000 070300000

, , , 47 46. , lookahead, , 8 ( - ) .

So

resultString = Regex.Replace(subjectString, @"(\+|\b00|\b)4[67](?=\d{8})", "0");

4770300000 004770300000 +4770300000 460000

070300000 070300000 070300000 460000

( , - ),

resultString = Regex.Replace(subjectString, @"^(\+|00)4[67](?=\d{8})", "0");

. !

0

070300000 , , f.e. 9

0
source

Source: https://habr.com/ru/post/1794395/


All Articles