You are here

public function ValidatingService::isValidNumber in International Phone 8

Same name and namespace in other branches
  1. 8.2 src/Helpers/ValidatingService.php \Drupal\phone_international\Helpers\ValidatingService::isValidNumber()
  2. 3.x src/Helpers/ValidatingService.php \Drupal\phone_international\Helpers\ValidatingService::isValidNumber()

Utility for international phone numbers.

Parameters

string $number: Phone number verification and validation.

Return value

bool Return number valid(TRUE) or invalid(FALSE).

Overrides isValid::isValidNumber

File

src/Helpers/ValidatingService.php, line 23

Class

ValidatingService
Class ValidatingService.

Namespace

Drupal\phone_international\Helpers

Code

public function isValidNumber($number) {
  $phoneUtil = PhoneNumberUtil::getInstance();
  try {
    $parseNumber = $phoneUtil
      ->parse($number);
    return $phoneUtil
      ->isValidNumber($parseNumber);
  } catch (NumberParseException $e) {
    Drupal::logger('phone_international')
      ->debug($e);
    return FALSE;
  }
}