Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Latest commit

 

History

History
58 lines (38 loc) · 1.26 KB

03-rules_country.md

File metadata and controls

58 lines (38 loc) · 1.26 KB

Country

Validates that a value is a valid country code.

Country(
    string $code = 'alpha-2',
    ?string $message = null
);

Basic Usage

// default alpha-2 code
Validator::country()->validate('pt'); // true

// alpha-3 code
Validator::country(code: 'alpha-3')->validate('prt'); // true

Note

An UnexpectedValueException will be thrown when the code value is not a valid option.

Note

An UnexpectedValueException will be thrown when the input value is not a string.

Options

code

type: string default: alpha-2

Set code type to validate the country. Check the official country codes list for more information.

Available options:

  • alpha-2: two-letter code
  • alpha-3: three-letter code

message

type: ?string default: The {{ name }} value is not a valid country.

Message that will be shown if the input value is not a valid country code.

The following parameters are available:

Parameter Description
{{ value }} The current invalid value
{{ name }} Name of the invalid value
{{ code }} Selected code type

Changelog

  • 0.2.0 Created