PHPackages                             brick/postcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. brick/postcode

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

brick/postcode
==============

A library to format and validate postcodes

0.6.1(2mo ago)861.7M↓14.9%15[1 issues](https://github.com/brick/postcode/issues)[3 PRs](https://github.com/brick/postcode/pulls)3MITPHPPHP ^8.2CI passing

Since Nov 21Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/brick/postcode)[ Packagist](https://packagist.org/packages/brick/postcode)[ GitHub Sponsors](https://github.com/BenMorel)[ RSS](/packages/brick-postcode/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (23)Used By (3)

Brick\\Postcode
===============

[](#brickpostcode)

[![](https://raw.githubusercontent.com/brick/brick/master/logo.png)](https://raw.githubusercontent.com/brick/brick/master/logo.png)

A PHP library to validate and format postcodes.

[![Build Status](https://github.com/brick/postcode/workflows/CI/badge.svg)](https://github.com/brick/postcode/actions)[![Coverage Status](https://camo.githubusercontent.com/45c88f760620b704f677b36fa21cda3d54132050aff47bfab18d93499602a45f/68747470733a2f2f636f6465636f762e696f2f6769746875622f627269636b2f706f7374636f64652f67726170682f62616467652e737667)](https://codecov.io/github/brick/postcode)[![Latest Stable Version](https://camo.githubusercontent.com/5ae8d15ea0fb9cf5ff4c7f0256e9d806aeeae6cd84944e95c1ad15454355bab0/68747470733a2f2f706f7365722e707567782e6f72672f627269636b2f706f7374636f64652f762f737461626c65)](https://packagist.org/packages/brick/postcode)[![Total Downloads](https://camo.githubusercontent.com/13c2053fcf79d53b8a13efc3fdbf2f626e7f04448bc1ae6c2b6ff31d16e91675/68747470733a2f2f706f7365722e707567782e6f72672f627269636b2f706f7374636f64652f646f776e6c6f616473)](https://packagist.org/packages/brick/postcode)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://opensource.org/licenses/MIT)

Introduction
------------

[](#introduction)

This library can format and validate postcodes for all countries having a postcode system.

Contributions are welcome, please feel free to open an issue or a pull request if you notice any mistake.

Installation
------------

[](#installation)

This library is installable via [Composer](https://getcomposer.org/):

```
composer require brick/postcode
```

Requirements
------------

[](#requirements)

This library requires PHP 8.2 or later.

Project status &amp; release process
------------------------------------

[](#project-status--release-process)

This library is still under development.

The current releases are numbered `0.x.y`. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), `y` is incremented.

**When a breaking change is introduced, a new `0.x` version cycle is always started.**

It is therefore safe to lock your project to a given release cycle, such as `0.6.*`.

If you need to upgrade to a newer release cycle, check the [release history](https://github.com/brick/postcode/releases) for a list of changes introduced by each further `0.x.0` version.

How to use it
-------------

[](#how-to-use-it)

```
use Brick\Postcode\PostcodeFormatter;

$formatter = new PostcodeFormatter();

$formatter->format('GB', 'WC2E9RZ'); // WC2E 9RZ
$formatter->format('US', '337014313'); // 33701-4313
```

Notes
-----

[](#notes)

- Postcodes are cleaned from optional separators (spaces and dashes) before validation. Misplaced or mismatched separators are not considered an error and will be ignored:

    ```
    $formatter->format('GB', 'WC-2E9RZ'); // WC2E 9RZ
    ```
- If `format()` is called with an unknown country code, an [UnknownCountryException](https://github.com/brick/postcode/blob/0.6.0/src/Exception/UnknownCountryException.php) is thrown:

    ```
    $formatter->format('XX', '12345'); // UnknownCountryException
    ```

    Note that a country with no postcode system is considered as unknown, even if the country code is a valid ISO 3166 code.
- If `format()` is called with an invalid postcode for the given country, an [InvalidPostcodeException](https://github.com/brick/postcode/blob/0.6.0/src/Exception/InvalidPostcodeException.php) is thrown:

    ```
    $formatter->format('GB', 'ABCDEFG'); // InvalidPostcodeException
    ```

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~158 days

Recently: every ~126 days

Total

20

Last Release

82d ago

PHP version history (5 changes)0.1.0PHP &gt;=7.1

0.2.5PHP ^7.1 || ^8.0

0.3.0PHP ^7.4 || ^8.0

0.5.0PHP ^8.1

0.6.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/57189121968030f0770811b461cc92f9c19c08f5c4767292f2ede48b7277cfad?d=identicon)[BenMorel](/maintainers/BenMorel)

---

Top Contributors

[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (306 commits)")[![chris-ware](https://avatars.githubusercontent.com/u/19684457?v=4)](https://github.com/chris-ware "chris-ware (1 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")[![grizzm0](https://avatars.githubusercontent.com/u/2905853?v=4)](https://github.com/grizzm0 "grizzm0 (1 commits)")[![jiripudil](https://avatars.githubusercontent.com/u/1042159?v=4)](https://github.com/jiripudil "jiripudil (1 commits)")[![mpesari](https://avatars.githubusercontent.com/u/11061725?v=4)](https://github.com/mpesari "mpesari (1 commits)")[![nigobo](https://avatars.githubusercontent.com/u/2266769?v=4)](https://github.com/nigobo "nigobo (1 commits)")[![rubentebogt](https://avatars.githubusercontent.com/u/8817394?v=4)](https://github.com/rubentebogt "rubentebogt (1 commits)")[![strotgen](https://avatars.githubusercontent.com/u/14982436?v=4)](https://github.com/strotgen "strotgen (1 commits)")[![wernerwa](https://avatars.githubusercontent.com/u/14849239?v=4)](https://github.com/wernerwa "wernerwa (1 commits)")[![weswaldix](https://avatars.githubusercontent.com/u/37552851?v=4)](https://github.com/weswaldix "weswaldix (1 commits)")

---

Tags

formattingphppostcodevalidationbrickpostcode

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/brick-postcode/health.svg)

```
[![Health](https://phpackages.com/badges/brick-postcode/health.svg)](https://phpackages.com/packages/brick-postcode)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)[xemlock/htmlpurifier-html5

HTML5 support for HTML Purifier

1052.9M11](/packages/xemlock-htmlpurifier-html5)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
