libphonenumber\ShortNumberInfo::isPossibleShortNumberForRegion PHP 메소드

isPossibleShortNumberForRegion() 공개 메소드

Check whether a short number is a possible number when dialled from a region, given the number in the form of a string, and the region where the number is dialled from. This provides a more lenient check than {@link #isValidShortNumber}.
public isPossibleShortNumberForRegion ( PhoneNumber | string $shortNumber, string $regionDialingFrom ) : boolean
$shortNumber PhoneNumber | string The short number to check
$regionDialingFrom string Region dialing From
리턴 boolean whether the number is a possible short number
    public function isPossibleShortNumberForRegion($shortNumber, $regionDialingFrom)
    {
        if ($shortNumber instanceof PhoneNumber) {
            if (!$this->regionDialingFromMatchesNumber($shortNumber, $regionDialingFrom)) {
                return false;
            }
        }
        $phoneMetadata = $this->getMetadataForRegion($regionDialingFrom);
        if ($phoneMetadata === null) {
            return false;
        }
        if ($shortNumber instanceof PhoneNumber) {
            $numberLength = strlen($this->getNationalSignificantNumber($shortNumber));
            return in_array($numberLength, $phoneMetadata->getGeneralDesc()->getPossibleLength());
        } else {
            /**
             * @deprecated Anyone who was using it and passing in a string with whitespace (or other
             *        formatting characters) would have been getting the wrong result. You should parse
             *        the string to PhoneNumber and use the method
             *        {@code #isPossibleShortNumberForRegion(PhoneNumber, String)}. This method will be
             *        removed in the next release.
             */
            return in_array(strlen($shortNumber), $phoneMetadata->getGeneralDesc()->getPossibleLength());
        }
    }

Usage Example

 public function testIsPossibleShortNumber()
 {
     $possibleNumber = new PhoneNumber();
     $possibleNumber->setCountryCode(33)->setNationalNumber(123456);
     $this->assertTrue($this->shortInfo->isPossibleShortNumber($possibleNumber));
     $this->assertTrue($this->shortInfo->isPossibleShortNumberForRegion($this->parse(123456, RegionCode::FR), RegionCode::FR));
     $impossibleNumber = new PhoneNumber();
     $impossibleNumber->setCountryCode(33)->setNationalNumber(9);
     $this->assertFalse($this->shortInfo->isPossibleShortNumber($impossibleNumber));
     // Note that GB and GG share the country calling code 44, and that this number is possible but
     // not valid.
     $gbNumber = new PhoneNumber();
     $gbNumber->setCountryCode(44)->setNationalNumber(11001);
     $this->assertTrue($this->shortInfo->isPossibleShortNumber($gbNumber));
 }
All Usage Examples Of libphonenumber\ShortNumberInfo::isPossibleShortNumberForRegion