PostalCodeRule extends Rule
Validates a postal code for a given country.
Tags
Table of Contents
Constants
- COUNTRY = 'country'
- The country parameter.
Properties
- $default : string
- The default ISO 3166-1 alpha-2 country code.
- $fillableParams : array<string|int, mixed>
- The internal list of fillable parameters.
- $message : string
- The internal message pattern.
Methods
- __construct() : mixed
- Creates a new PostalCodeRule instance.
- check() : bool
- Checks whether the given value satisfies the condition.
- country() : static
- The country code of the postalCode regex pattern.
Constants
COUNTRY
The country parameter.
public
mixed
COUNTRY
= 'country'
Properties
$default
The default ISO 3166-1 alpha-2 country code.
protected
string
$default
= \org\iso\ISO3166_1::FR
$fillableParams
The internal list of fillable parameters.
protected
array<string|int, mixed>
$fillableParams
= [self::COUNTRY]
$message
The internal message pattern.
protected
string
$message
= ":attribute is not a valid postal code with the value ':value'."
Methods
__construct()
Creates a new PostalCodeRule instance.
public
__construct([array<string|int, mixed>|string|null $country = null ][, string $default = ISO3166_1::FR ]) : mixed
Parameters
- $country : array<string|int, mixed>|string|null = null
-
An ISO 3166-1 alpha-2 country code or a list of valid country codes.
- $default : string = ISO3166_1::FR
-
The default ISO 3166-1 alpha-2 country code (By default ISO3166_1::FR)
check()
Checks whether the given value satisfies the condition.
public
check(mixed $value) : bool
Parameters
- $value : mixed
-
The value to check.
Tags
Return values
bool —True if the value satisfies the condition.
country()
The country code of the postalCode regex pattern.
public
country(array<string|int, mixed>|string|null $value) : static
Parameters
- $value : array<string|int, mixed>|string|null
-
The country code of the postal code.