sirprize/postal-code-validator

Validate Formatting Of World-Wide Postal Codes

Installs: 1 711 184

Dependents: 1

Suggesters: 0

Security: 0

Stars: 77

Watchers: 5

Forks: 27

Open Issues: 3

pkg:composer/sirprize/postal-code-validator

1.5.0 2023-11-24 06:06 UTC

This package is auto-updated.

Last update: 2025-09-24 10:11:40 UTC


README

Validate Formatting of World-Wide Postal Codes according this "List of postal codes" article on Wikipedia

Installation

composer require sirprize/postal-code-validator

Usage

Check If Country Is Supported

use Sirprize\PostalCodeValidator\Validator;

$validator = new Validator();
$validator->hasCountry('CH'); // returns true

Check If Postal Code Is Properly Formatted

use Sirprize\PostalCodeValidator\Validator;

$validator = new Validator();
$validator->isValid('CH', 'usjU87jsdf'); // returns false
$validator->isValid('CH', '3007'); // returns true

Get The Possible Formats For a Specific Country

use Sirprize\PostalCodeValidator\Validator;

$validator = new Validator();
$validator->getFormats('GB'); // returns ['@@## #@@', '@#@ #@@', '@@# #@@', '@@#@ #@@', '@## #@@', '@# #@@']

Formatting

  • # = 0-9
  • @ = a-zA-Z

Country Codes

Postal-code-validator uses ISO 3166 2-letter country codes

License

See LICENSE.