getRegionCodeForNumber
getRegionCodeForNumber(number) is used to gets the region where a phone number is from.
Usage
Using Standard JavaScript:
// Create an instance of PhoneNumberUtil
const phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();
// Parse number with US country code and keep raw input
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');
// Get region code of number
console.log(phoneUtil.getRegionCodeForNumber(number));
// US
Using ECMAScript (ES):
import libphonenumbers from 'libphonenumbers';
// Create an instance of PhoneNumberUtil
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();
// Parse number with US country code and keep raw input
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');
// Get region code of number
console.log(phoneUtil.getRegionCodeForNumber(number));
// US