Automattic\WooCommerce\StoreApi\Utilities

ValidationUtils::validate_state()publicWC 1.0

Validate provided state against a countries list of defined states.

If there are no defined states for a country, any given state is valid.

Method of the class: ValidationUtils{}

No Hooks.

Return

true|false. Valid or not valid.

Usage

$ValidationUtils = new ValidationUtils();
$ValidationUtils->validate_state( $state, $country );
$state(string) (required)
State name or code (sanitized).
$country(string) (required)
Country code.

ValidationUtils::validate_state() code WC 9.3.1

public function validate_state( $state, $country ) {
	$states = $this->get_states_for_country( $country );

	if ( count( $states ) && ! in_array( \wc_strtoupper( $state ), array_map( '\wc_strtoupper', array_keys( $states ) ), true ) ) {
		return false;
	}

	return true;
}