public function testNormaliseStripAlphaCharacters() { $inputNumber = "034-56&+a#234"; $expectedOutput = "03456234"; $this->assertEquals($expectedOutput, $this->phoneUtil->normalizeDigitsOnly($inputNumber), "Conversion did not correctly remove alpha character"); }
private function matchesEmergencyNumberHelper($number, $regionCode, $allowPrefixMatch) { $number = PhoneNumberUtil::extractPossibleNumber($number); $matcher = new Matcher(PhoneNumberUtil::$PLUS_CHARS_PATTERN, $number); if ($matcher->lookingAt()) { // Returns false if the number starts with a plus sign. WE don't believe dialling the country // code before emergency numbers (e.g. +1911) works, but later, if that proves to work, we can // add additional logic here to handle it. return false; } $metadata = $this->getMetadataForRegion($regionCode); if ($metadata === null || !$metadata->hasEmergency()) { return false; } $emergencyNumberPattern = $metadata->getEmergency()->getNationalNumberPattern(); $normalizedNumber = PhoneNumberUtil::normalizeDigitsOnly($number); $emergencyMatcher = new Matcher($emergencyNumberPattern, $normalizedNumber); return !$allowPrefixMatch || in_array($regionCode, self::$regionsWhereEmergencyNumbersMustBeExact) ? $emergencyMatcher->matches() : $emergencyMatcher->lookingAt(); }