How to Extract Country Code from National Phone Number?

355 views
Skip to first unread message

Asnan A

unread,
Jul 19, 2023, 7:52:19 AM7/19/23
to libphonenumber-discuss
Hey Everyone!
I want to extract country code from a national phone number. How do I do that?
I am now first parsing the number using PhoneNumberUtil() and then using getCountryCode() but it is throwing an error that "Invalid Country Code" 

If you have any solution, please guide me

Thanks 
number.PNG

Marcos Porto mariño

unread,
Jul 19, 2023, 11:20:46 AM7/19/23
to libphonenumber-discuss
Hi,
in the C# implementation, it's somethink like:

try {
  let _phone = new PhoneNumber.PhoneNumberUtil();

  const _n = _phone.parse(number, "");

  const countryCode = _phone.getRegionCodeForNumber(_n);

  console.log(countryCode); 
} catch (error) {
  console.log(error);
  throw error;
}

I hope this helps you.
Best regards.
Marcos Porto.
Reply all
Reply to author
Forward
0 new messages