respect-validation/docs/validators/PostalCode.md
Henrique Moody 7db3bea8a6
Enhance LintSpdxCommand with contributor tracking and header normalization
Improves SPDX header linting to ensure consistent license metadata across
the codebase.

Key changes:

- Enforce deterministic tag ordering (License-Identifier, FileCopyrightText,
  FileContributor) to ensure consistency, prevent merge conflicts, and
  simplify code reviews

- Add contributor alias mapping to consolidate contributors with multiple
  emails or name variations (e.g., "nickl-" → "Nick Lombard")

- Add --contributions-strategy option with "blame" (current code authors)
  and "log" (all historical contributors) to support different attribution
  philosophies

- Add optional path argument to lint specific files or directories

- Add --fix option to automatically correct header issues

Assisted-by: Claude Code (claude-opus-4-5-20251101)
2026-02-03 15:23:20 +01:00

2.2 KiB

PostalCode

  • PostalCode(string $countryCode)
  • PostalCode(string $countryCode, bool $formatted)

Validates whether the input is a valid postal code or not.

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:

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.

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