本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::isPossibleNumber方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::isPossibleNumber方法的具體用法?PHP PhoneNumberUtil::isPossibleNumber怎麽用?PHP PhoneNumberUtil::isPossibleNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::isPossibleNumber方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isValidNumber
/**
* Performs the actual validation of the phone number.
*
* @param mixed $number
* @param null $country
* @return bool
*/
protected function isValidNumber($number, $country = null)
{
try {
// Throws NumberParseException if not parsed correctly against the supplied country.
// If no country was given, tries to discover the country code from the number itself.
$phoneNumber = $this->lib->parse($number, $country);
// Lenient validation; doesn't need a country code.
if ($this->lenient) {
return $this->lib->isPossibleNumber($phoneNumber);
}
// For automatic detection, the number should have a country code.
// Check if type is allowed.
if ($phoneNumber->hasCountryCode() && (empty($this->types) || in_array($this->lib->getNumberType($phoneNumber), $this->types))) {
// Automatic detection:
if ($this->autodetect) {
// Validate if the international phone number is valid for its contained country.
return $this->lib->isValidNumber($phoneNumber);
}
// Validate number against the specified country.
return $this->lib->isValidNumberForRegion($phoneNumber, $country);
}
} catch (NumberParseException $e) {
// Proceed to default validation error.
}
return false;
}
示例2: testIsNotPossibleNumber
public function testIsNotPossibleNumber()
{
$this->assertFalse($this->phoneUtil->isPossibleNumber(self::$usLongNumber));
$this->assertFalse($this->phoneUtil->isPossibleNumber(self::$internationalTollFreeTooLong));
$number = new PhoneNumber();
$number->setCountryCode(1)->setNationalNumber(253000);
$this->assertFalse($this->phoneUtil->isPossibleNumber($number));
$number->clear();
$number->setCountryCode(44)->setNationalNumber(300);
$this->assertFalse($this->phoneUtil->isPossibleNumber($number));
$this->assertFalse($this->phoneUtil->isPossibleNumber("+1 650 253 00000", RegionCode::US));
$this->assertFalse($this->phoneUtil->isPossibleNumber("(650) 253-00000", RegionCode::US));
$this->assertFalse($this->phoneUtil->isPossibleNumber("I want a Pizza", RegionCode::US));
$this->assertFalse($this->phoneUtil->isPossibleNumber("253-000", RegionCode::US));
$this->assertFalse($this->phoneUtil->isPossibleNumber("1 3000", RegionCode::GB));
$this->assertFalse($this->phoneUtil->isPossibleNumber("+44 300", RegionCode::GB));
$this->assertFalse($this->phoneUtil->isPossibleNumber("+800 1234 5678 9", RegionCode::UN001));
}
示例3: parse
private function parse()
{
if ($this->phoneNumberProto) {
// from phoneNumberProto
$this->country_code = $this->phoneNumberProto->getCountryCode();
$this->country_code_plus_sign = "+" . $this->country_code;
$this->national_number = $this->phoneNumberProto->getNationalNumber();
$this->extension = $this->phoneNumberProto->getExtension();
$this->country_code_source = $this->phoneNumberProto->getCountryCodeSource();
if (isset($this->countryCodeSourcesText[$this->country_code_source])) {
$this->country_code_source_text = $this->countryCodeSourcesText[$this->country_code_source];
}
$this->raw_input = $this->phoneNumberProto->getRawInput();
$this->preferred_domestic_carrier_code = $this->phoneNumberProto->getPreferredDomesticCarrierCode();
// from validation
$this->is_possible_number = $this->phoneUtil->isPossibleNumber($this->phoneNumberProto);
$this->is_valid_number = $this->phoneUtil->isValidNumber($this->phoneNumberProto);
$this->region_code_for_number = $this->phoneUtil->getRegionCodeForNumber($this->phoneNumberProto);
$this->number_type = $this->phoneUtil->getNumberType($this->phoneNumberProto);
$this->number_type_text = $this->phoneUtil->getNumberType($this->phoneNumberProto);
if (isset($this->phoneNumberTypesText[$this->number_type])) {
$this->number_type_text = $this->phoneNumberTypesText[$this->number_type];
} else {
$this->number_type_text = "OTHER";
}
$this->is_mobile_number = in_array($this->number_type, [PhoneNumberType::FIXED_LINE_OR_MOBILE, PhoneNumberType::MOBILE]);
// from formatting
$this->format_e164 = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::E164);
$this->format_international = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::INTERNATIONAL);
$this->format_national = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::NATIONAL);
$this->format_rfc3966 = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::RFC3966);
// from additional
$phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder::getInstance();
$this->description = $phoneNumberOfflineGeocoder->getDescriptionForNumber($this->phoneNumberProto, 'en');
$phoneNumberToCarrierMapper = PhoneNumberToCarrierMapper::getInstance();
$this->carrier_name = $phoneNumberToCarrierMapper->getNameForNumber($this->phoneNumberProto, 'en');
$phoneNumberToTimeZonesMapper = PhoneNumberToTimeZonesMapper::getInstance();
$this->timezones = $phoneNumberToTimeZonesMapper->getTimeZonesForNumber($this->phoneNumberProto);
}
}