libphonenumber\PhoneNumberUtil::isLeadingZeroPossible PHP Method

isLeadingZeroPossible() public method

Checks whether the country calling code is from a region whose national significant number could contain a leading zero. An example of such a region is Italy. Returns false if no metadata for the country is found.
public isLeadingZeroPossible ( integer $countryCallingCode ) : boolean
$countryCallingCode integer
return boolean
    public function isLeadingZeroPossible($countryCallingCode)
    {
        $mainMetadataForCallingCode = $this->getMetadataForRegionOrCallingCode($countryCallingCode, $this->getRegionCodeForCountryCode($countryCallingCode));
        if ($mainMetadataForCallingCode === null) {
            return false;
        }
        return (bool) $mainMetadataForCallingCode->isLeadingZeroPossible();
    }

Usage Example

 public function testIsLeadingZeroPossible()
 {
     $this->assertTrue($this->phoneUtil->isLeadingZeroPossible(39));
     // Italy
     $this->assertFalse($this->phoneUtil->isLeadingZeroPossible(1));
     // USA
     $this->assertFalse($this->phoneUtil->isLeadingZeroPossible(800));
     // International toll free numbers
     $this->assertFalse($this->phoneUtil->isLeadingZeroPossible(888));
     // Not in metadata file, just default to false.
 }
PhoneNumberUtil