Check that a value is a valid phone number.

@param  string|array $check   Value to check (string or array)
@param  string       $regex   Regular expression to use
@param  string       $country Country code (defaults to 'all')
@return boolean Success
179767
public static function phone($check, $regex = null, $country = 'all')
	{
		if (is_array($check))
		{
			extract(self::_defaults($check));
		}

		if ($regex === null)
		{
			switch ($country)
			{
				case 'us':
				case 'ca':
				case 'can': // deprecated three-letter-code
				case 'all':
					// includes all NANPA members.
					// see http://en.wikipedia.org/wiki/North_American_Numbering_Plan#List_of_NANPA_countries_and_territories
					$regex = '/^(?:(?:\+?1\s*(?:[.-]\s*)?)?';

					// Area code 555, X11 is not allowed.
					$areaCode = '(?![2-9]11)(?!555)([2-9][0-8][0-9])';
					$regex .= '(?:\(\s*' . $areaCode . '\s*\)|' . $areaCode . ')';
					$regex .= '\s*(?:[.-]\s*)?)';

					// Exchange and 555-XXXX numbers
					$regex .= '(?!(555(?:\s*(?:[.\-\s]\s*))(01([0-9][0-9])|1212)))';
					$regex .= '(?!(555(01([0-9][0-9])|1212)))';
					$regex .= '([2-9]1[02-9]|[2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)';

					// Local number and extension
					$regex .= '?([0-9]{4})';
					$regex .= '(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/';
				break;
			}
		}
		if (empty($regex))
		{
			return self::_pass('phone', $check, $country);
		}
		return self::_check($check, $regex);
	}
1104902
public function formatForCountry($country)
    {
        if (! static::isValidCountryCode($country)) {
            throw CountryCodeException::invalid($country);
        }

        return $this->lib->formatOutOfCountryCallingNumber(
            $this->getPhoneNumberInstance(),
            $country
        );
    }
127316
protected function checkUriRegexMatch($regex, $returnOnTrue = null, $returnOnFalse = null)
    {
        if (\preg_match('#^' . $regex . '$#', $this->uri) === 1) {
            return $returnOnTrue ?? true;
        }

        return $returnOnFalse ?? false;
    }
1177312
public function validate($locale)
    {
        if (!$locale) {
            return false;
        }
        $lang = $this->langFromLocale($locale);
        $region = $this->countryFromLocale($locale);
        if (!$lang || !$region) {
            return false;
        }

        // Check the configurable whitelist
        $localeCode = strtolower($lang) . '_' . strtoupper($region);
        $locales = $this->getLocales();

        if (array_key_exists($localeCode, $locales)
            || array_key_exists(strtolower($localeCode), $locales)
        ) {
            return true;
        }

        // Fallback
        return strcasecmp($lang, $region)
            && strcasecmp($lang, $locale)
            && strcasecmp($region, $locale);
    }
1325920
public function match($regex)
    {
        $match = array();
        if($this->isValidRegex($regex) && preg_match($regex, $this->toString(), $match)===1)
        {
            return new ObjectArray($match);
        }
        return null;
    }
882689
public function whereRegex($expr, $regex, $flags = '')
    {
        $key = $expr;
        $this->_conditions[] = $expr . ' REGEXP ' . (strpos($flags, 'i') !== false ? '' : 'BINARY ') . ':' . $key;
        $this->_bind[$key] = $regex;

        return $this;
    }
53058
public function check($regexp)
    {
        if (preg_match($regexp, $this->getRemainder(), $matches)) {
            if (strlen($matches[0]) &&
                mb_strpos($this->getRemainder(), $matches[0]) === 0) {
                return $this->setState($matches);
            }
        }
        return $this->setState();
    }
941958
protected function onInvalidEventAttributeValidate($key, $check = [], $rule = NULL)
    {
        $this->validate[] = $rule ?: $key;

        return $this->required()->onInvalidEventCustomValidity($key, $check);
    }
81305
public static function check($regExp, $string)
    {
        $regExpType = array(
            'email'       => '/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([_a-z0-9]+\.)+[a-z]{2,5}$/',
            'numeric'     => '/^[0-9]+$/',
            'zip'         => '/^[1-9]\d{5}$/',
            'phone'       => '/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/',
            'mobile'      => '/^1\d{10}$/',
            'mobilePhone' => '/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,12}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/',
            'qq'          => '/^[1-9]*[1-9][0-9]*$/',
            'china'       => '/[\u4e00-\u9fa5]/',
            'idcard'      => '/\d{15}|\d{18}/',
        );
        $regExpValue = array_key_exists($regExp, $regExpType) ? $regExpType[$regExp] : $regExp;

        if (substr($regExpValue, 0, 1) != '/') {
            throw new ephpException('<font color="red">在默认库中 ' . $regExp . ' 的规则匹配失败，系统使用你的输入作为正则规则，但你输入的正则语法错误。</font> 合法的规则如： /^[0-9]+$/ 请检查后重试！', 1554);
        }
        //dump($regExpValue);
        return preg_match($regExpValue, $string);
    }
33832
private function isFormatValid()
    {
        $countryCode = $this->getCountryCode();
        $accountIdentification = $this->getAccountIdentification();

        return !(preg_match('/' . static::$ibanFormatMap[$countryCode][1] . '/', $accountIdentification) !== 1);
    }
428222
public static function comparison($input, $check, $mode) {
        switch (mb_strtolower($mode)) {
            case 'greater':
            case 'gt':
            case '>':
                return ($input > $check);
            break;
            case 'greaterorequal':
            case 'gte':
            case '>=':
                return ($input >= $check);
            break;
            case 'less':
            case 'lt':
            case '<':
                return ($input < $check);
            break;
            case 'lessorequal':
            case 'lte':
            case '<=':
                return ($input <= $check);
            break;
            case 'equal':
            case 'eq':
            case '==':
            case '=':
                return ($input == $check);
            break;
            case 'notequal':
            case 'neq':
            case 'ne':
            case '!=':
                return ($input != $check);
            break;
            default:
                throw new InvalidArgumentException(sprintf('Unsupported mode %s for %s', $mode, __METHOD__));
            break;
        }
    }
193667
public static function money($check, $symbolPosition = 'left')
    {
        $money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1,2})?';
        if ($symbolPosition === 'right') {
            $regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u';
        } else {
            $regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u';
        }

        return static::_check($check, $regex);
    }
1197939
public function regex($regex, $error) {
        if ($this->_exist) {
            array_push($this->_constraints, ['type' => self::REGEX, 'value' => $regex, 'message' => $error]);
        }

        return $this;
    }
321619
public static function validateZipCode($zipCode, $country) {
        switch (strtoupper($country)) {
            case 'NL':
                if (preg_match('/^[1-9]{1}[0-9]{3}[A-Z]{2}$/', $zipCode))
                    return true;
                break;
            case 'BE':
                if (preg_match('/^[1-9]{4}$/', $zipCode))
                    return true;
                break;
            case 'DE':
                if (preg_match('/^[1-9]{5}$/', $zipCode))
                    return true;
                break;
        }

        return false;
    }
928984
private function hasValue(array $check, string $value): bool
    {
        if (empty($check[$value])) {
            return false;
        }

        return true;
    }
1191132
public function validateReCaptchaValue($originFile, $validate)
	{
		// The key 'RECAPTCHA_LANG' must match the list provided by Google, or be left empty
		// If any other key is used, we will show an error
		if (array_key_exists('RECAPTCHA_LANG', $validate) && !in_array($validate['RECAPTCHA_LANG'], $this->reCaptchaLanguages))
		{
			// The supplied value doesn't match the allowed values
			$this->output->addMessage(Output::ERROR, 'reCaptcha must match a language/country code on https://developers.google.com/recaptcha/docs/language - if no code exists for your language you can use "en" or leave the string empty', $originFile, 'RECAPTCHA_LANG');
		}
	}
97272
public function ifMatches(string $regex)
    {
        if ($this->value->isMatchedBy($regex)) {
            return $this->value->value();
        }

        $this->paramErrors->append($this->paramName, 'FIELD_WRONG_VALUE');
        return null;
    }