Validate a Number

@param string $phone Phone number.
@return array|bool Phone data. False on failure.
979921
public static function match($phone='') {
		if (! \is_string($phone)) {
			if (\is_numeric($phone)) {
				$phone = (string) $phone;
			}
			else {
				return false;
			}
		}

		phone::sanitize_phone($phone);
		if (false === $phone) {
			return false;
		}

		// Test the number with and without the prefix.
		$test = array($phone);
		$tmp = \ltrim($phone, '0');
		if (0 === \strpos($tmp, \strval(static::PREFIX))) {
			$test[] = \substr($tmp, \strlen(static::PREFIX));
		}

		// Do they match the patterns?
		foreach ($test as $t) {
			foreach (static::PATTERNS as $p) {
				if (\preg_match("/^($p)$/", $t)) {
					// Should match a specific type.
					$types = static::types($t);
					if (! \count($types)) {
						continue;
					}

					$out = phone::TEMPLATE;
					$out['country'] = static::CODE;
					$out['prefix'] = static::PREFIX;
					$out['region'] = static::REGION;
					$out['types'] = $types;
					$out['number'] = '+' . static::PREFIX . ' ' . static::format($t);

					return $out;
				}
			}
		}

		return false;
	}
1260697
public static function isValid(string $number) : bool
    {
        if (ctype_digit($number)) {
            return self::checksum($number) === 0;
        }

        return false;
    }
461366
public static function isPhoneNumber($value) {
        if (!is_string($value)) return false;

        // handle empty value
        $value = trim($value);
        if (!strlen($value)) return false;

        // remove spaces
        $value = str_replace(' ', '', $value);

        // match numbers from BE, ES, BG, CH, A, UK, DE
        return (bool) preg_match('/^(00|\+)(32|34|359|41|43|44|49)-?[1-9](-?[0-9]){2,}$/', $value);

        // TODO: implement via https://github.com/giggsey/libphonenumber-for-php
    }
372609
private function validateNumber(): bool
    {
        if ($this->options['require-number'] === true) {
            if (!\preg_match('/[0-9]/', (string)$this->value)) {
                $this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_NUMBER);
                return false;
            }
        }
        return true;
    }
298032
private function validateMethod($method)
    {
        $prefix = substr($method, 0, 3);

        if ($prefix === 'get' || $prefix === 'set' || $prefix === 'has') {
            return lcfirst(substr($method, 3));
        }

        $prefix = substr($prefix, 0, 2);

        if ($prefix === 'is') {
            return lcfirst(substr($method, 2));
        }
    }
734614
public function validate($input)
    {
        /**
         * Validation criteria:
         * - 8 or 9 digits (only numbers!)
         * - Be able to pass the '11 test'
         * - Musn't contain any information.
         *   Cannot implement at this stage, not clear enough defined! Is 1337 information?
         * - Can not be sequential (nummeric)
         * - Is not 900000000 through 999999999 (test numbers)
         *
         * Based on public information: http://nl.wikipedia.org/wiki/Burgerservicenummer
         */

        // Validate: 8 or 9 digits (only numbers!)
        if (strlen($input) < 8 || strlen($input) > 9) {
            return false;
        }

        // Check if they are actually numbers
        // Alternatively, use ctype_digit($input) !
        if (preg_match('/[^0-9]/', $input)) {
            return false;
        }

        // See if the number passes the Eleventest (http://nl.wikipedia.org/wiki/Elfproef)
        if ($this->elevenTest($input)) {
            return false;
        }

        // Check if the numbers are sequential
        // Will not match when sequential numbers are used
        if (preg_match('/\d{5}/u', $input)) {
            return false;
        }

        // Validate if the number is not in the test range!
        return filter_var(
            $input,
            FILTER_VALIDATE_INT,
            array('options' => array('min_range' => '900000000', 'max_range' => '999999999'))
        );
    }
874686
public function validatePhoneNumber($phoneNumber, $verificationCode)
    {
        Piwik::checkUserIsNotAnonymous();

        $phoneNumbers = $this->retrievePhoneNumbers();

        if (isset($phoneNumbers[$phoneNumber])) {
            if ($verificationCode == $phoneNumbers[$phoneNumber]) {

                $phoneNumbers[$phoneNumber] = null;
                $this->savePhoneNumbers($phoneNumbers);
                return true;
            }
        }

        return false;
    }
402706
public static function validate($language)
    {
        if (\in_array(\strtolower($language), self::$validLanguageCode, true)) {
            return \strtolower($language);
        }

        return false;
    }
1074692
protected function validateMethod( $method ){
		if( !is_int( $method ) )
			throw new \InvalidArgumentException( 'Method must be integer' );
		if( !in_array( $method, array( self::METHOD_SOCKET, self::METHOD_PING ) ) )
			throw new \RangeException( 'Invalid method' );
		return $method;
	}
871897
private static function isValidChecksum($number)
    {
        $map = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 4, 6, 8, 1, 3, 5, 7, 9);
        $sum = 0;
        $last = strlen($number) - 1;
        for ($i = 0; $i <= $last; $i++) {
            $sum += $map[$number[$last - $i] + ($i & 1) * 10];
        }

        return ($sum % 10 == 0);
    }
520853
public function validation($error)
    {
        $url = $this->controller->request->getRequestTarget();
        $status = $code = $error->getCode();
        try {
            $this->controller->response = $this->controller->response->withStatus($status);
        } catch (Exception $e) {
            $status = 422;
            $this->controller->response = $this->controller->response->withStatus($status);
        }

        $sets = [
            'code' => $code,
            'url' => h($url),
            'message' => $error->getMessage(),
            'error' => $error,
            'errorCount' => $error->getValidationErrorCount(),
            'errors' => $error->getValidationErrors(),
            '_serialize' => ['code', 'url', 'message', 'errorCount', 'errors']
        ];
        $this->controller->set($sets);

        return $this->_outputMessage('error400');
    }
560961
public static function checkPhoneNumber($phoneNumber) {
        $phoneNumber = self::cleanPhoneNumber($phoneNumber);

        if (!empty($phoneNumber) && strlen($phoneNumber) > self::$_inputFldMaxLength['PhoneNumber']) {
            $errorMessage = 'The value for phone number can be no more than ' . self::$_inputFldMaxLength['PhoneNumber'] . ' characters, Please try again after making corrections';
            throw new HpsInvalidRequestException(
            HpsExceptionCodes::INVALID_PHONE_NUMBER, $errorMessage
            );
        }
        return $phoneNumber;
    }
1288249
public function validate($value)
    {
        if (!is_numeric($value)) {
            return false;
        }
        // Convert possible strings to number
        $number = $value + 0;

        return is_double($number) || !$this->strict && is_int($number);
    }
1100481
protected function validate($value)
    {
        if (!parent::validate($value)) {
            return false;
        }

        if (count($value) < $this->min) {
            $this->messenger->add(new StringType(self::ERR_MIN));
            return false;
        }

        if ($this->max !== -1 && (count($value) > $this->max)) {
            $this->messenger->add(new StringType(self::ERR_MAX));
            return false;
        }

        $validator = $this->validator;
        foreach ($value as $k => $v) {
            if (!$validator($v, $this->messenger)) {
                $this->messenger->add(new StringType(sprintf(self::ERR_ITEM, (string)$k)));
                return false;
            }
        }

        return true;
    }
183740
public function validate($value)
    {
        // generic pattern match if it's numeric [float/int/double]
        if (!preg_match('/^\d{0,}[.,]?\d*$/', (string)$value)) return false;

        $this->value = $value;

        return true;
    }
1140213
public static function validate($code = '', $key = -1)
    {
        if (strlen($key) < 1) {
            return false;
        }

        if (!is_numeric($key)) {
            return false;
        }

        if (!is_string($code)) {
            return false;
        }

        if (strlen($code) < 2) {
            return false;
        }

        $numerals = str_split($code);
        $rank = array_reverse(array_keys($numerals));
        $orderedNumerals = array();
        foreach ($rank as $i => $rankValue) {
            $orderedNumerals[$rankValue + 1] = $numerals[$i];
        }
        $results = array();
        foreach ($orderedNumerals as $cle => $value) {
            $results[$value] = ($cle % 2 == 0) ? ((int) $value * 1) : ((int) $value * 2);
        }
        $sum = 0;
        foreach ($results as $cle => $value) {
            $sum += array_sum(str_split($value));
        }
        $validKey = str_split($sum);
        $validKey = 10 - array_pop($validKey);

        return $key === $validKey;
    }
1149541
public static function phone_format( $phone )
    {
        $phone = preg_replace( '/[^0-9]/', '', $phone );

        if ( strlen( $phone ) < 10 )
        {
            throw new ValidateInputException( null, 400, [ 'error_code' => 14, 'error_params' => [ 'номер телефона' ] ] );
        }

        if ( !empty( $phone ) && strlen( $phone ) == 11 && $phone[0] == '8' )
        {
            $phone[0] = '7';
        }
        elseif ( strlen( $phone ) == 10 )
        {
            $phone = '7' . $phone;
        }

        return $phone;
    }