Validates a postcode

@param string $postcode to be validated
@return boolean
330466
public function validate($postcode)
    {
        $url = '/postcodes/' . rawurlencode($postcode) . '/validate';
        $request = new Request('GET', $url);
        $response = $this->httpTransport($request);

        return ($response && (200 === $response->status) && $response->result);
    }
1072510
private function isError(int $statusCode): bool
    {
        if ($this->statusCodeValidator) {
            return call_user_func($this->statusCodeValidator, $statusCode);
        }

        return $statusCode >= 400 && $statusCode < 600;
    }
606537
public function determinePostalType($postalcode)
    {
        $postalcode = str_replace(' ', '', $postalcode);

        if (strlen($postalcode) == 6) {
            return ['nl_sixpp' => $postalcode];
        }

        if (strlen($postalcode) == 4) {
            return ['nl_fourpp' => $postalcode];
        }

        throw new \Exception('No valid postalcode was found (nl_sixpp or nl_fourpp)');
    }
1159215
public function validate($data) {
        // allow paramtype to be a custom regex if it is the form of /pattern/
        if (preg_match('#^/.*/$#', $this->paramtype)) {
            if (preg_match($this->paramtype, $data)) {
                return true;
            } else {
                return get_string('validateerror', 'admin');
            }

        } else if ($this->paramtype === PARAM_RAW) {
            return true;

        } else {
            $cleaned = clean_param($data, $this->paramtype);
            if ("$data" === "$cleaned") { // implicit conversion to string is needed to do exact comparison
                return true;
            } else {
                return get_string('validateerror', 'admin');
            }
        }
    }
924754
public function validateConfirmationCode($code)
    {
        $ccAttribute = $this->confirmCodeAttribute;
        if (!$ccAttribute || empty($ccAttribute)) {
            return true;
        }
        return $this->$ccAttribute === $code;
    }
168671
protected function validate($code)
    {
        $color = str_replace(['rgb', '(', ')', ' '], '', DefinedColor::find($code, 1));
        if (preg_match('/^(\d{1,3}),(\d{1,3}),(\d{1,3})$/', $color, $matches)) {
            if ($matches[1] > 255 || $matches[2] > 255 || $matches[3] > 255) {
                return false;
            }
            return $color;
        }
        return false;
    }
620871
public function validateCodeCountryState()
    {
        $field = 'code';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $updating = $this->getUpdating();

        if (isset($updating['code']) && $updating['code'] === $value) {
            return true;
        }

        $label = $this->translation->text('Code');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        $existing = $this->state->getList(array('code' => $value, 'country' => $this->getSubmitted('country')));

        if (!empty($existing)) {
            $this->setErrorExists($field, $label);
            return false;
        }

        return true;
    }
1298233
protected function validateResponseCode($code) {
        $code = (int) $code;

        try {
            Assertion::range($code, 100, 599, sprintf('Response code must be between 100 and 599, got %d.', $code));
        } catch (AssertionFailure $e) {
            throw new InvalidArgumentException($e->getMessage());
        }

        return $code;
    }
1143595
public function validateCode($code)
    {
        $coupon = $this->_controller->getRepository()->find(array('code' => $code));

        if ($coupon && !$coupon->expired()) {
            $discount = $coupon->discount * 100;
            $this->setMessage(AnTranslator::sprintf('COM-SUBSCRIPTIONS-VALID-COUPON', $discount));
            return true;
        } else {
            $this->setMessage(AnTranslator::_('COM-SUBSCRIPTIONS-INVALID-COUPON'));
            return false;
        }
    }
1167903
public function validate(&$error = null)
    {
        if (!$this->isCountryCodeValid()) {
            $error = 'IBAN country code not valid or not supported';
        } elseif (!$this->isLengthValid()) {
            $error = 'IBAN length is invalid';
        } elseif (!$this->isFormatValid()) {
            $error = 'IBAN format is invalid';
        } elseif (!$this->isChecksumValid()) {
            $error = 'IBAN checksum is invalid';
        } else {
            $error = '';
            return true;
        }

        return false;
    }
1124881
protected function validateCode($code)
    {
        if (is_integer($code)) {
            return true;
        }

        // Plug it back in and see what we get
        if (is_string($code)) {
            return $this->set($code);
        }

        if (is_array($code)) {
            return $this->validateCodeArray($code);
        }

        return false;
    }
482889
public function validate($value)
    {
        if ($this->notBeEmpty($value)) {
            $value = json_decode($value);
            if ($value !== null) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
118316
protected function validate($code)
    {
        list($class, $index) = property_exists($this, 'lightness') ? ['hsl', 2] : ['hsv', 3];
        $color = str_replace([$class, '(', ')', ' ', '%'], '', DefinedColor::find($code, $index));
        if (preg_match('/^(\d{1,3}),(\d{1,3}),(\d{1,3})$/', $color, $matches)) {
            if ($matches[1] > 360 || $matches[2] > 100 || $matches[3] > 100) {
                return false;
            }
            return $color;
        }
        return false;
    }
499031
public function status($code = 200)
    {
        if (!isset(self::$codes[$code])) {
            return false;
        }
        $this->header($code . ' ' . self::$codes[$code]);
        return true;
    }
789571
public static function isBodyAllowed($code)
    {
        if (!isset(self::$codesDescriptions[$code])) {
            throw new InvalidArgumentException("Invalid code $code specified");
        }

        return ($code >= self::OK && $code !== self::NO_CONTENT && $code !== self::NOT_MODIFIED);
    }
161514
public function isValid($value = null, $context = null)
    {
        if (!is_scalar($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $this->setValue($value);

        $country = $this->getCountry();

        if (!array_key_exists($country, self::$postCodeRegex) && array_key_exists($country, $context)) {
            $country = $context[$country];
        }

        if (!array_key_exists($country, self::$postCodeRegex)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        $format = self::$postCodeRegex[$country];

        if ($format[0] !== '/') {
            $format = '/^' . $format;
        }

        if ($format[strlen($format) - 1] !== '/') {
            $format .= '$/';
        }

        if (!preg_match($format, $value)) {
            $this->error(self::NO_MATCH);

            return false;
        }

        return true;
    }
1328284
public function postcodeLookupBulk($postcodes)
    {
        $headers = ['Content-Type' => 'application/json'];
        $body = ['postcodes' => $postcodes];

        $request = new Request('POST', '/postcodes', $headers, json_encode($body));

        return $this->httpTransport($request);
    }