Sanitize Country

Make sure the country is an ISO code.

@param string $country Country.
@return bool True/false.
517127
public static function sanitize_country(string &$country='') {
		r_sanitize::country($country);

		if (
			! $country ||
			! \in_array($country, data\prefixes::COUNTRIES, true)
		) {
			$country = false;
		}

		return true;
	}
1063760
public function setCountry($country)
    {
        if ($country === null) {
            throw new Klarna_ArgumentNotSetException('Country');
        }
        if (is_numeric($country)) {
            if (!is_int($country)) {
                $country = intval($country);
            }
            $this->country = $country;
            return;
        }
        if (strlen($country) == 2 || strlen($country) == 3) {
            $this->setCountry(KlarnaCountry::fromCode($country));
            return;
        }
        throw new KlarnaException("Failed to set country! ($country)");
    }
647845
public function setCountry($country)
    {
        $this->set('country', $country);

        $vat = $this->getService('repos:subscriptions.vat')->find(array('country' => $country));

        if ($vat) {
            $this->setVat($vat);
        }

        return $this;
    }
1148835
public function To($country)
    {
        $country = $this->library->getMetadataForRegion($country);
        $this->instance->setCountryCode($country->getCountryCode());
        return $this;
    }
937067
public function isValidLocale($language, $country)
    {
        return ($this->getLanguage() === $language && $this->getCountry() === $country)
            || (empty($this->getLanguage()) && empty($this->getCountry()));
    }
701000
def passed_country(country)
      code = country_prefix(country)
      if Core::PLUS_SIGN == @original[0] && code && !sanitized.start_with?(code)
        # in case number passed with + but it doesn't start with passed
        # country prefix
        country = nil
      end
      country
    end
219631
public static function isValidEmail(string $email, bool $sanitize = true): bool
    {
        // Remove all illegal characters from email
        if (true === $sanitize) {
            $email = filter_var($email, FILTER_SANITIZE_EMAIL);
        }
        return !filter_var($email, FILTER_VALIDATE_EMAIL) === false;
    }
767775
public function ofCountry($country)
    {
        $countries = is_array($country) ? $country : func_get_args();

        $instance = clone $this;
        $instance->countries = array_unique(
            array_merge($instance->countries, static::parseCountries($countries))
        );

        return $instance;
    }
33832
private function isFormatValid()
    {
        $countryCode = $this->getCountryCode();
        $accountIdentification = $this->getAccountIdentification();

        return !(preg_match('/' . static::$ibanFormatMap[$countryCode][1] . '/', $accountIdentification) !== 1);
    }
802303
protected function validateFieldAddress($field)
    {
        if ($this->isExcluded($field) || $this->isError('country')) {
            return null;
        }

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

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

        $format = $this->getCountryFormatAddress();

        if (empty($format[$field]['required'])) {
            return null;
        }

        if (!isset($value) || $value === '' || mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $format[$field]['name'], 1, 255);
            return false;
        }

        return true;
    }
520169
def valid_for_country?(country)
      country = country.to_s.upcase
      tdata = analyze(sanitized, passed_country(country))
      tdata.find do |iso2, data|
        country == iso2 && data[:valid].any?
      end.is_a? Array
    end
986215
public function hydrateFlag($country)
    {
        $country = countriesCollect($country)->overwrite(
            ['flag' => $this->repository->makeAllFlags($country)]
        );

        return $country;
    }
1257366
public static boolean isSEPACountry(String countryCode) {
        int index = indexOf(countryCode);
        if (index > -1) {
            return (CountryCodes.COUNTRY_IBAN_LENGTHS[index] & SEPA) == SEPA;
        }
        return false;
    }
585401
public function getLanguageForCountry($country = null)
    {
        if ($country === null) {
            $country = $this->_country;
        }
        // Since getLanguage defaults to EN, check so we actually have a match
        $language = KlarnaCountry::getLanguage($country);
        if (KlarnaCountry::checkLanguage($country, $language)) {
            return $language;
        }
        return false;
    }
1142320
private function _checkCountry(&$country)
    {
        if (!isset($country)) {
            throw new Klarna_ArgumentNotSetException("Country");
        }
        if (is_numeric($country) && !is_int($country)) {
            $country = intval($country);
        }
        if (!is_numeric($country) || !is_int($country)) {
            throw new Klarna_InvalidTypeException("Country", "integer");
        }
    }
606375
public function isValidDelivery(Country $country)
    {
        return $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->isVirtual();
    }
813557
private function isValidCountries(array $countries): void
    {
        if (!empty($countries)) {
            foreach ($countries as $country) {
                $this->isValidCountry($country);
            }
        }
    }