respect-validation/docs/validators/PostalCode.md
Alexandre Gomes Gaigalas bd48bdcda4 Lint Changelog format in validator docs
Introduces a Markdown linter for checking the Changelog format.

"See Also" was transformed into a section to make it easier to
handle it with the `Content` class. The "Related" linter was
simplified to reflect that change too.

An additional "alignment" parameter was added to markdown table
generators, allowing the padding and headers to be explicitly
marked with a specific left (-1), middle (0) or right(1)
alignment.

Existing files were fixed using the `fix` option after the
changes.
2026-01-26 19:11:00 +00:00

76 lines
2.2 KiB
Markdown

<!--
SPDX-FileCopyrightText: (c) Respect Project Contributors
SPDX-License-Identifier: MIT
-->
# PostalCode
- `PostalCode(string $countryCode)`
- `PostalCode(string $countryCode, bool $formatted)`
Validates whether the input is a valid postal code or not.
```php
v::postalCode('BR')->assert('02179000');
// Validation passes successfully
v::postalCode('BR')->assert('02179-000');
// Validation passes successfully
v::postalCode('US')->assert('02179-000');
// → "02179-000" must be a valid postal code on "US"
v::postalCode('US')->assert('55372');
// Validation passes successfully
v::postalCode('PL')->assert('99-300');
// Validation passes successfully
```
By default, `PostalCode` won't validate the format (puncts, spaces), unless you pass `$formatted = true`:
```php
v::postalCode('BR', true)->assert('02179000');
// → "02179000" must be a valid postal code on "BR"
v::postalCode('BR', true)->assert('02179-000');
// Validation passes successfully
```
Message template for this validator includes `{{countryCode}}`.
Extracted from [GeoNames](http://www.geonames.org/).
## Templates
### `PostalCode::TEMPLATE_STANDARD`
| Mode | Template |
| ---------: | :------------------------------------------------------------- |
| `default` | {{subject}} must be a valid postal code on {{countryCode}} |
| `inverted` | {{subject}} must not be a valid postal code on {{countryCode}} |
## Template placeholders
| Placeholder | Description |
| ------------- | ---------------------------------------------------------------- |
| `countryCode` | |
| `subject` | The validated input or the custom validator name (if specified). |
## Categorization
- Localization
- Strings
## Changelog
| Version | Description |
| ------: | :------------------------------------------------ |
| 2.3.0 | Add option to validate formatting |
| 2.2.4 | Cambodian postal codes now support 5 and 6 digits |
| 0.7.0 | Created |
## See Also
- [CountryCode](CountryCode.md)
- [Iban](Iban.md)