protected function getRegionCodeForNumberFromRegionList(PhoneNumber $number, array $regionCodes)
{
$nationalNumber = $this->getNationalSignificantNumber($number);
foreach ($regionCodes as $regionCode) {
// If leadingDigits is present, use this. Otherwise, do full validation.
// Metadata cannot be null because the region codes come from the country calling code map.
$metadata = $this->getMetadataForRegion($regionCode);
if ($metadata->hasLeadingDigits()) {
$nbMatches = preg_match('/' . $metadata->getLeadingDigits() . '/', $nationalNumber, $matches, PREG_OFFSET_CAPTURE);
if ($nbMatches > 0 && $matches[0][1] === 0) {
return $regionCode;
}
} elseif ($this->getNumberTypeHelper($nationalNumber, $metadata) != PhoneNumberType::UNKNOWN) {
return $regionCode;
}
}
return null;
}