Helper method to check that the country calling code of the number matches the region it's
being dialed from.
@param PhoneNumber $number
@param string $regionDialingFrom
@return bool
499830
protected function regionDialingFromMatchesNumber(PhoneNumber $number, $regionDialingFrom)
    {
        $regionCodes = $this->getRegionCodesForCountryCode($number->getCountryCode());

        return in_array($regionDialingFrom, $regionCodes);
    }
727497
function(n, countryCode){

        const number = phoneUtil.parse(n, countryCode),
            isPossibleNumber = phoneUtil.isPossibleNumber(number),
	        res = {
                input: n,
                countryCode: countryCode,
                isPossibleNumber: isPossibleNumber,
                isPossibleNumberWithReason: phoneUtil.isPossibleNumberWithReason(number)
	        };

        if(isPossibleNumber){
            res.isPossibleNumber = true;
            res.isNumberValid = phoneUtil.isValidNumber(number);
            res.countryCode = countryCode;
            res.formatted = phoneUtil.formatInOriginalFormat(number, countryCode);
            res.national = phoneUtil.format(number, PNF.NATIONAL);
            res.international = phoneUtil.format(number, PNF.INTERNATIONAL)
        }

        switch (phoneUtil.isPossibleNumberWithReason(number)){

            case PNV.IS_POSSIBLE:
                res.isPossibleNumberWithReason = 'IS_POSSIBLE';
            break;

            case PNV.INVALID_COUNTRY_CODE:
                res.isPossibleNumberWithReason = 'INVALID_COUNTRY_CODE';
            break;

            case PNV.TOO_SHORT:
                res.isPossibleNumberWithReason = 'TOO_SHORT';
            break;

            case PNV.TOO_LONG:
                res.isPossibleNumberWithReason = 'TOO_LONG';
            break;
        }

        return res;
    }
385618
public function lookupTimeZonesForNumber(PhoneNumber $number)
    {
        $phonePrefix = $number->getCountryCode() . PhoneNumberUtil::getInstance()->getNationalSignificantNumber(
                $number
            );

        return $this->lookupTimeZonesForNumberKey($phonePrefix);
    }
1245358
protected function prefixNumberWithCountryCallingCode($countryCallingCode, $numberFormat, &$formattedNumber)
    {
        switch ($numberFormat) {
            case PhoneNumberFormat::E164:
                $formattedNumber = static::PLUS_SIGN . $countryCallingCode . $formattedNumber;
                return;
            case PhoneNumberFormat::INTERNATIONAL:
                $formattedNumber = static::PLUS_SIGN . $countryCallingCode . ' ' . $formattedNumber;
                return;
            case PhoneNumberFormat::RFC3966:
                $formattedNumber = static::RFC3966_PREFIX . static::PLUS_SIGN . $countryCallingCode . '-' . $formattedNumber;
                return;
            case PhoneNumberFormat::NATIONAL:
            default:
                return;
        }
    }
20555
public static function findByCountryAndCode($country, $code)
    {
        $country = is_object($country) ? $country->id : $country;

        return ProvinceProxy::byCountry($country)
                            ->where('code', $code)
                            ->take(1)
                            ->get()
                            ->first();
    }
1257366
public static boolean isSEPACountry(String countryCode) {
        int index = indexOf(countryCode);
        if (index > -1) {
            return (CountryCodes.COUNTRY_IBAN_LENGTHS[index] & SEPA) == SEPA;
        }
        return false;
    }
51942
public function isVATCountry($countryCode)
    {
        $country = $this->getCountry($countryCode);

        return !is_null($country) && $country->usedVATOnCurrentDate();
    }
922305
public function checkOneAndOnlyOneCountry()
    {
        $countryCount = $this->getRegionZonesByTypeName(RegionZoneTypeInterface::COUNTRY)->count();
        if ($countryCount !== 1) {
            throw new OneAndOnlyOneException(
                sprintf(
                    'Region "%s" should belong to one and only one RegionZone of type "Country", %d given.',
                    $this->getName(),
                    $countryCount
                )
            );
        }
    }
775881
public function read($phoneNumber = null, $countryCode = null)
    {
        if(empty($phoneNumber)) {
            throw new InvalidArgumentException('The phone number cannot be empty.');
        }

        $query = null;
        if ($countryCode != null) {
            $query = array("countryCode" => $countryCode);
        }
        $ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ;
        list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query, null);
        return $this->processRequest($body);
    }
317668
function isValid(number, countryCode) {
    try {
        var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
        var numberObj = phoneUtil.parseAndKeepRawInput(number, countryCode);
        return phoneUtil.isValidNumber(numberObj);
    } catch (e) {
        return false;
    }
}
784065
function FormatNumber(regionMetaData, number, intl) {
    // We lazily parse the format description in the meta data for the region,
    // so make sure to parse it now if we haven't already done so.
    ParseFormat(regionMetaData);
    var formats = regionMetaData.formats;
    if (!formats) {
      return null;
    }
    for (var n = 0; n < formats.length; ++n) {
      var format = formats[n];
      // The leading digits field is optional. If we don't have it, just
      // use the matching pattern to qualify numbers.
      if (format.leadingDigits && !format.leadingDigits.test(number))
        continue;
      if (!format.pattern.test(number))
        continue;
      if (intl) {
        // If there is no international format, just fall back to the national
        // format.
        var internationalFormat = format.internationalFormat;
        if (!internationalFormat)
          internationalFormat = format.nationalFormat;
        // Some regions have numbers that can't be dialed from outside the
        // country, indicated by "NA" for the international format of that
        // number format pattern.
        if (internationalFormat == "NA")
          return null;
        // Prepend "+" and the country code.
        number = "+" + regionMetaData.countryCode + " " +
                 number.replace(format.pattern, internationalFormat);
      } else {
        number = number.replace(format.pattern, format.nationalFormat);
        // The region has a national prefix formatting rule, and it can be overwritten
        // by each actual number format rule.
        var nationalPrefixFormattingRule = regionMetaData.nationalPrefixFormattingRule;
        if (format.nationalPrefixFormattingRule)
          nationalPrefixFormattingRule = format.nationalPrefixFormattingRule;
        if (nationalPrefixFormattingRule) {
          // The prefix formatting rule contains two magic markers, "$NP" and "$FG".
          // "$NP" will be replaced by the national prefix, and "$FG" with the
          // first group of numbers.
          var match = number.match(SPLIT_FIRST_GROUP);
          if (match) {
            var firstGroup = match[1];
            var rest = match[2];
            var prefix = nationalPrefixFormattingRule;
            prefix = prefix.replace("$NP", regionMetaData.nationalPrefix);
            prefix = prefix.replace("$FG", firstGroup);
            number = prefix + rest;
          }
        }
      }
      return (number == "NA") ? null : number;
    }
    return null;
  }
244212
function checkExecParamsRegionSuccessError(region, success, error)
{
	var caller = checkExecParamsRegionSuccessError.caller.name

	if (typeof region != 'object') {
		console.error('Error: region parameter is not an object in: ' + caller);
		return false;
	}

	if (typeof success != 'function') {
		console.error('Error: success parameter is not a function in: ' + caller);
		return false;
	}

	if (typeof error != 'function') {
		console.error('Error: error parameter is not a function in: ' + caller);
		return false;
	}

	return true;
}
75873
protected function matchesPossibleNumberAndNationalNumber($number, PhoneNumberDesc $numberDesc)
    {
        if (count($numberDesc->getPossibleLength()) > 0 && !in_array(strlen($number), $numberDesc->getPossibleLength())) {
            return false;
        }

        return $this->matcherAPI->matchNationalNumber($number, $numberDesc, false);
    }
328190
public function ValidTax($country = null, $region = null)
    {
        if (empty($country)) {
            // First try and get the locale from the member
            $member = Security::getCurrentUser();

            if ($member && $member->getLocale()) {
                $country = $member->getLocale();
            }
        }

        if (empty($country)) {
            $country = i18n::get_locale();
        }

        if (strlen($country) > 2) {
            $country = Locale::getRegion($country);
        }

        $filter = [
            'Global' => 1,
            "Zones.Regions.CountryCode" => $country
        ];

        $rates = $this
            ->Rates()
            ->filterAny($filter);

        if (isset($region)) {
            $rates = $rates->filter("Zones.Regions.Code", $region);
        }

        return $rates->first();
    }
473646
public function numbersCancel ($country_code, $msisdn) {
			$country_code = strtoupper($country_code);

			$tmp = $this->apiCall('cancel_number', array('country_code'=>$country_code, 'msisdn'=>$msisdn));
			return ($tmp['http_code'] === 200);
		}
851623
public function setSenderPhone($areaCode, $number = null)
    {
        $param = $areaCode;
        if ($this->sender == null) {
            $this->sender = new PagSeguroSender();
        }
        if ($param instanceof PagSeguroPhone) {
            $this->sender->setPhone($param);
        } else {
            $this->sender->setPhone(new PagSeguroPhone($param, $number));
        }
    }
828830
function ParseNumber(number, defaultRegion) {
    var ret;

    // Remove formating characters and whitespace.
    number = PhoneNumberNormalizer.Normalize(number);

    // If there is no defaultRegion, we can't parse international access codes.
    if (!defaultRegion && number[0] !== '+')
      return null;

    // Detect and strip leading '+'.
    if (number[0] === '+')
      return ParseInternationalNumber(number.replace(LEADING_PLUS_CHARS_PATTERN, ""));

    // Lookup the meta data for the given region.
    var md = FindMetaDataForRegion(defaultRegion.toUpperCase());

    // See if the number starts with an international prefix, and if the
    // number resulting from stripping the code is valid, then remove the
    // prefix and flag the number as international.
    if (md.internationalPrefix.test(number)) {
      var possibleNumber = number.replace(md.internationalPrefix, "");
      ret = ParseInternationalNumber(possibleNumber)
      if (ret)
        return ret;
    }

    // This is not an international number. See if its a national one for
    // the current region. National numbers can start with the national
    // prefix, or without.
    if (md.nationalPrefixForParsing) {
      // Some regions have specific national prefix parse rules. Apply those.
      var withoutPrefix = number.replace(md.nationalPrefixForParsing,
                                         md.nationalPrefixTransformRule || '');
      ret = ParseNationalNumber(withoutPrefix, md)
      if (ret)
        return ret;
    } else {
      // If there is no specific national prefix rule, just strip off the
      // national prefix from the beginning of the number (if there is one).
      var nationalPrefix = md.nationalPrefix;
      if (nationalPrefix && number.indexOf(nationalPrefix) == 0 &&
          (ret = ParseNationalNumber(number.substr(nationalPrefix.length), md))) {
        return ret;
      }
    }
    ret = ParseNationalNumber(number, md)
    if (ret)
      return ret;

    // Now lets see if maybe its an international number after all, but
    // without '+' or the international prefix.
    ret = ParseInternationalNumber(number)
    if (ret)
      return ret;

    // If the number matches the possible numbers of the current region,
    // return it as a possible number.
    if (md.possiblePattern.test(number))
      return new NationalNumber(md, number);

    // We couldn't parse the number at all.
    return null;
  }