當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PhoneNumberUtil::isValidNumberForRegion方法代碼示例

本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::isValidNumberForRegion方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::isValidNumberForRegion方法的具體用法?PHP PhoneNumberUtil::isValidNumberForRegion怎麽用?PHP PhoneNumberUtil::isValidNumberForRegion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在libphonenumber\PhoneNumberUtil的用法示例。


在下文中一共展示了PhoneNumberUtil::isValidNumberForRegion方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testIsValidNumberForRegion

 public function testIsValidNumberForRegion()
 {
     $number = "+33 6 76 83 51 85";
     $region = "DE";
     $phoneNumber = $this->phoneUtil->parse($number, $region);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($phoneNumber, "DE"));
 }
開發者ID:RonLab1987,項目名稱:ride-workshop,代碼行數:7,代碼來源:Issue34Test.php

示例2: 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;
 }
開發者ID:xfxf,項目名稱:Laravel-Phone,代碼行數:33,代碼來源:PhoneValidator.php

示例3: testEveryRegionHasExampleNumber

 /**
  * @dataProvider regionList
  * @param string $regionCode
  */
 public function testEveryRegionHasExampleNumber($regionCode)
 {
     $exampleNumber = $this->phoneNumberUtil->getExampleNumber($regionCode);
     $this->assertNotNull($exampleNumber, "None found for region " . $regionCode);
     /*
      * Check the number is valid
      */
     $e164 = $this->phoneNumberUtil->format($exampleNumber, PhoneNumberFormat::E164);
     $phoneObject = $this->phoneNumberUtil->parse($e164, 'ZZ');
     $this->assertEquals($phoneObject, $exampleNumber);
     $this->assertTrue($this->phoneNumberUtil->isValidNumber($phoneObject));
     $this->assertTrue($this->phoneNumberUtil->isValidNumberForRegion($phoneObject, $regionCode));
 }
開發者ID:ayurmedia,項目名稱:faveo-helpdesk,代碼行數:17,代碼來源:ExampleNumbersTest.php

示例4: testIsValidNumberForRegion

 /**
  * 
  */
 public function testIsValidNumberForRegion()
 {
     // This number is valid for the Bahamas, but is not a valid US number.
     $this->assertTrue($this->phoneUtil->isValidNumber(self::$bsNumber));
     $this->assertTrue($this->phoneUtil->isValidNumberForRegion(self::$bsNumber, RegionCode::BS));
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion(self::$bsNumber, RegionCode::US));
     $bsInvalidNumber = new PhoneNumber();
     $bsInvalidNumber->setCountryCode(1)->setNationalNumber(2421232345);
     // This number is no longer valid.
     $this->assertFalse($this->phoneUtil->isValidNumber($bsInvalidNumber));
     // La Mayotte and Reunion use 'leadingDigits' to differentiate them.
     $reNumber = new PhoneNumber();
     $reNumber->setCountryCode(262)->setNationalNumber(262123456);
     $this->assertTrue($this->phoneUtil->isValidNumber($reNumber));
     $this->assertTrue($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::RE));
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::YT));
     // Now change the number to be a number for La Mayotte.
     $reNumber->setNationalNumber(269601234);
     $this->assertTrue($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::YT));
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::RE));
     // This number is no longer valid for La Reunion.
     $reNumber->setNationalNumber(269123456);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::YT));
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::RE));
     $this->assertFalse($this->phoneUtil->isValidNumber($reNumber));
     // However, it should be recognised as from La Mayotte, since it is valid for this region.
     $this->assertEquals(RegionCode::YT, $this->phoneUtil->getRegionCodeForNumber($reNumber));
     // This number is valid in both places.
     $reNumber->setNationalNumber(800123456);
     $this->assertTrue($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::YT));
     $this->assertTrue($this->phoneUtil->isValidNumberForRegion($reNumber, RegionCode::RE));
     $this->assertTrue($this->phoneUtil->isValidNumberForRegion(self::$internationalTollFree, RegionCode::UN001));
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion(self::$internationalTollFree, RegionCode::US));
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion(self::$internationalTollFree, RegionCode::ZZ));
     $invalidNumber = new PhoneNumber();
     // Invalid country calling codes.
     $invalidNumber->setCountryCode(3923)->setNationalNumber(2366);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($invalidNumber, RegionCode::ZZ));
     $invalidNumber->setCountryCode(3923)->setNationalNumber(2366);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($invalidNumber, RegionCode::UN001));
     $invalidNumber->setCountryCode(0)->setNationalNumber(2366);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($invalidNumber, RegionCode::UN001));
     $invalidNumber->setCountryCode(0);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($invalidNumber, RegionCode::ZZ));
 }
開發者ID:jpresult,項目名稱:libphonenumber-for-php,代碼行數:48,代碼來源:PhoneNumberUtilTest.php

示例5: getCountryNameForNumber

 /**
  * Returns the customary display name in the given language for the given territory the phone
  * number is from. If it could be from many territories, nothing is returned.
  *
  * @param PhoneNumber $number
  * @param string $locale
  * @return string
  */
 protected function getCountryNameForNumber(PhoneNumber $number, $locale)
 {
     $regionCodes = $this->phoneUtil->getRegionCodesForCountryCode($number->getCountryCode());
     if (count($regionCodes) === 1) {
         return $this->getRegionDisplayName($regionCodes[0], $locale);
     } else {
         $regionWhereNumberIsValid = 'ZZ';
         foreach ($regionCodes as $regionCode) {
             if ($this->phoneUtil->isValidNumberForRegion($number, $regionCode)) {
                 if ($regionWhereNumberIsValid !== 'ZZ') {
                     // If we can't assign the phone number as definitely belonging to only one territory,
                     // then we return nothing.
                     return "";
                 }
                 $regionWhereNumberIsValid = $regionCode;
             }
         }
         return $this->getRegionDisplayName($regionWhereNumberIsValid, $locale);
     }
 }
開發者ID:giggsey,項目名稱:libphonenumber-for-php,代碼行數:28,代碼來源:PhoneNumberOfflineGeocoder.php

示例6: isValid

 /**
  * @param string|Entities\IPhone $number
  * @param string $country
  * @param string|NULL $type
  *
  * @return bool
  *
  * @throws Exceptions\NoValidCountryException
  * @throws Exceptions\NoValidTypeException
  */
 public function isValid($number, $country = 'AUTO', $type = NULL)
 {
     // Check if country is valid
     $country = $this->validateCountry($country);
     // Check if phone type is valid
     $type = $type !== NULL ? $this->validateType($type) : NULL;
     try {
         // Parse string into phone number
         $phoneNumber = $this->phoneNumberUtil->parse((string) $number, $country);
         if ($type !== NULL && $this->phoneNumberUtil->getNumberType($phoneNumber) !== $type) {
             return FALSE;
         }
         // Automatic detection:
         if ($country == 'AUTO') {
             // Validate if the international phone number is valid for its contained country
             return (bool) $this->phoneNumberUtil->isValidNumber($phoneNumber);
         }
         // Validate number against the specified country
         return (bool) $this->phoneNumberUtil->isValidNumberForRegion($phoneNumber, $country);
     } catch (libphonenumber\NumberParseException $ex) {
         return FALSE;
     }
 }
開發者ID:iPublikuj,項目名稱:phone,代碼行數:33,代碼來源:Phone.php

示例7: isValidNumberForRegion

 public function isValidNumberForRegion($country_code)
 {
     return $this->phoneUtil->isValidNumberForRegion($this->phoneNumber, $country_code);
 }
開發者ID:someline,項目名稱:starter-framework,代碼行數:4,代碼來源:PhoneNumberModel.php

示例8: isValid

 public function isValid($value)
 {
     if (!is_scalar($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $country = $this->getCountry();
     $supportedCountries = $this->libPhoneNumber->getSupportedRegions();
     if (!in_array($country, $supportedCountries)) {
         $this->error(self::UNSUPPORTED);
         return false;
     }
     try {
         $numberProto = $this->libPhoneNumber->parse($value, $country);
     } catch (NumberParseException $e) {
         $this->error(self::INVALID_NUMBER);
         return false;
     }
     if (!$this->libPhoneNumber->isValidNumber($numberProto)) {
         $this->error(self::INVALID_NUMBER);
         return false;
     }
     $region = $this->libPhoneNumber->getRegionCodeForNumber($numberProto);
     if ($this->libPhoneNumber->isValidNumberForRegion($numberProto, $region)) {
         return true;
     }
     $this->error(self::NO_MATCH);
     return false;
 }
開發者ID:uthando-cms,項目名稱:uthando-common,代碼行數:29,代碼來源:PhoneNumber.php


注:本文中的libphonenumber\PhoneNumberUtil::isValidNumberForRegion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。