IsoCodes\PhoneNumber::validate PHP Method

validate() public static method

public static validate ( string $phoneNumber, string $country = null ) : boolean
$phoneNumber string
$country string
return boolean
    public static function validate($phoneNumber, $country = null)
    {
        $phoneNumber = trim($phoneNumber);
        if (empty($phoneNumber)) {
            return false;
        }
        $country = strtoupper($country);
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $numberProto = $phoneUtil->parse($phoneNumber, $country);
        } catch (NumberParseException $e) {
            return false;
        }
        return $phoneUtil->isValidNumber($numberProto);
    }

Usage Example

 /**
  * @param mixed  $value
  * @param string $country
  *
  * @dataProvider getInvalidValues
  */
 public function testInvalidValues($value, $country)
 {
     $this->assertFalse(PhoneNumber::validate($value, $country));
 }
All Usage Examples Of IsoCodes\PhoneNumber::validate
PhoneNumber