libphonenumber\ShortNumberInfo::connectsToEmergencyNumber PHP Méthode

connectsToEmergencyNumber() public méthode

This method accepts a string, rather than a PhoneNumber, because it needs to distinguish cases such as "+1 911" and "911", where the former may not connect to an emergency service in all cases but the latter would. This method takes into account cases where the number might contain formatting, or might have additional digits appended (when it is okay to do that in the specified region).

public connectsToEmergencyNumber ( string $number, string $regionCode ) : boolean
$number string the phone number to test
$regionCode string the region where the phone number if being dialled
Résultat boolean whether the number might be used to connect to an emergency service in the given region
    public function connectsToEmergencyNumber($number, $regionCode)
    {
        return $this->matchesEmergencyNumberHelper($number, $regionCode, true);
    }

Usage Example

 public function testConnectsToEmergencyNumber_ZW()
 {
     // Zimbabwe doesn't have any metadata in the test metadata.
     $this->assertFalse($this->shortInfo->connectsToEmergencyNumber("911", RegionCode::ZW));
     $this->assertFalse($this->shortInfo->connectsToEmergencyNumber("01312345", RegionCode::ZW));
     $this->assertFalse($this->shortInfo->connectsToEmergencyNumber("0711234567", RegionCode::ZW));
 }