Attempts to match a parenthesized expression to find a hostname and an
address.  Returns true if the expression matched, and either hostname or
address were found.

@param string $value
@param string $hostname
@param string $address
@return boolean
555006
private function matchHostPart($value, &$hostname, &$address) {
        $matches = [];
        $pattern = '~^(?P<name>[a-z0-9\-]+\.[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P<addr>[a-f\d\.\:]+)\])?$~i';
        if (preg_match($pattern, $value, $matches)) {
            if (!empty($matches['name'])) {
                $hostname = $matches['name'];
            }
            if (!empty($matches['addr'])) {
                $address = $matches['addr'];
            }
            return true;
        }
        return false;
    }
1036351
protected function matchHost($host)
    {
        if (empty($this->host)) {
            return true;
        }

        $host = preg_replace('/^[^:]+:\/\//i', '', $host);
        $regex = str_replace('\{basename\}', '.*', preg_quote($this->host));

        return preg_match('/^' . $regex . '$/i', $host);
    }
974119
private function matchValue($value, $pattern)
    {
        // basic check
        if ($value == $pattern) {
            return true;
        }

        // simple check in case of optional param
        if ($pattern == '?') {
            return true;
        }

        // simple match in case pattern is just "*"
        if ($pattern == '*' && $value != '') {
            return true;
        }

        // more complex match in case when wildcard is part of a larger match
        $pattern = str_replace('*', '(.+)', $pattern);

        // regex match
        if (strpos($pattern, '(') !== false || strpos($pattern, '[') !== false || strpos($pattern, '\\') !== false) {
            return preg_match('#^' . $pattern . '$#', $value);
        }

        return false;
    }
1237561
protected function isValidDomain($hostname)
    {
        return preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $hostname)
            && preg_match("/^.{1,253}$/", $hostname)
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $hostname)
            && !preg_match("/^\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}$/", $hostname);
    }
1305166
private function isValid($pattern, $hostname)
    {
        return 0 === strpos($pattern, '/') && (1 + strrpos($pattern, '/')) === \strlen($pattern)
            ? (bool) preg_match($pattern, $hostname)
            : fnmatch($pattern, $hostname);
    }
413932
public function isMatch(Address $address)
    {
        if (!is_null($address->getBin()) && !is_null($this->bin) && $address->getBin() !== $this->bin) {
            return false;
        }
        if (!is_null($address->getKey()) && !is_null($this->key) && $address->getKey() !== $this->key) {
            return false;
        }
        return true;
    }
1296050
protected function findDomainsByHostnamePattern($hostnamePattern)
    {
        return array_filter(
            $this->domainRepository->findAll()->toArray(),
            function ($domain) use ($hostnamePattern) {
                return fnmatch($hostnamePattern, $domain->getHostname());
            }
        );
    }
1288820
private function matchAddr($addr1, $addr2, $len = 0, $chunklen = 32)
    {
        for (; $len > 0; $len -= $chunklen, next($addr1), next($addr2)) {
            $shift = $len >= $chunklen ? 0 : $chunklen - $len;
            if ((current($addr1) >> $shift) !== (current($addr2) >> $shift)) {
                return false;
            }
        }

        return true;
    }
949053
public static function checkEmailAddress($value) {
        $value = filter_var(trim($value),FILTER_SANITIZE_EMAIL);
        
        //validate the email address format
        if(!empty($value) && filter_var($value, FILTER_VALIDATE_EMAIL) === false){            
            throw new HpsInvalidRequestException(
                HpsExceptionCodes::INVALID_EMAIL_ADDRESS, 'Invalid email address'
            );
        }

        //validate length of input data and throw exception
        if (!empty(self::$_inputFldMaxLength['Email']) && strlen($value) > self::$_inputFldMaxLength['Email']) {            
            $errorMessage = "The value for Email can be no more than " . self::$_inputFldMaxLength['Email'] . ' characters, Please try again after making corrections';
            throw new HpsInvalidRequestException(
                HpsExceptionCodes::INVALID_INPUT_LENGTH, $errorMessage
            );
        }
        return $value;
    }
761845
public function contains(AddressInterface $address)
    {
        $result = false;
        if ($address->getAddressType() === $this->getAddressType()) {
            $cmp = $address->getComparableString();
            $from = $this->getComparableStartString();
            if ($cmp >= $from) {
                $to = $this->getComparableEndString();
                if ($cmp <= $to) {
                    $result = true;
                }
            }
        }

        return $result;
    }
252954
public static function url(string $value): bool
    {
        $result = filter_var($value, FILTER_VALIDATE_URL);
        return is_string($result) && $value === $result;
    }
408455
function equals( $other ) {
		if( ! ( $other instanceof Address ) ) {
			return false;
		}
		return $this === $other
			|| $this->asString() === $other->asString();
	}
664942
public function matchesDomain($domain)
    {
        if (!$this->_data['domain']) {
            return false;
        }

        $hostDomain = strtolower($domain);
        $cookieDomain = ltrim(strtolower($this->_data['domain']), '.');

        if (!$cookieDomain || !strcmp($domain, $cookieDomain)) {
            return true;
        }

        if (filter_var($hostDomain, FILTER_VALIDATE_IP)) {
            return false;
        }

        return (bool) preg_match('~\.' . preg_quote($cookieDomain) . '$~', $hostDomain);
    }
1207065
public function is_extension($name, $value, $extensions){
        if(! $this->not_empty($name, $value)){
            return TRUE;
        }
        $extensions= explode(',', $extensions);
        $ok= TRUE;
        if($this->isMultiple($value)){
            foreach ($value['name'] as $name) {
                $ext = pathinfo($name, PATHINFO_EXTENSION);
                if (in_array($ext, $extensions)){
                    $ok= FALSE;
                    break;
                }
            }
        }else{
            $ext = pathinfo($value['name'], PATHINFO_EXTENSION);
            $ok= (in_array($ext, $extensions));
        }        
        
        if($ok){
            return TRUE;
        }else{
            $this->add_message($name, 'is_extension', array('extensions' => $extensions));
            return FALSE;
        }
    }
639656
public static function url(string $value):bool
    {
        $value = (string)$value;
        $valid = filter_var($value, FILTER_VALIDATE_URL);
        return $valid !== false;
    }
828691
public function equals(HostnameInterface $hostname): bool
    {
        return $this->getDomainParts() === $hostname->getDomainParts() && $this->getTld() === $hostname->getTld();
    }
434165
protected function validateUrlActive($field, $value)
    {
        foreach (static::$validUrlPrefixes as $prefix) {
            if (\strpos($value, $prefix) !== false) {
                $host = \parse_url(\strtolower($value), PHP_URL_HOST);

                return \checkdnsrr($host, 'A') || \checkdnsrr($host, 'AAAA') || \checkdnsrr($host, 'CNAME');
            }
        }

        return false;
    }