Skip to content

Check the province prefix of Spanish postcodes - #32

Open
PierreQueyroi wants to merge 1 commit into
brick:mainfrom
PierreQueyroi:es-province-prefix
Open

PierreQueyroi wants to merge 1 commit into
brick:mainfrom
PierreQueyroi:es-province-prefix

Conversation

@PierreQueyroi

Copy link
Copy Markdown

The first two digits of a Spanish postcode identify the province or autonomous city, from 01 (Álava) to 52 (Melilla). ESFormatter accepted any five digits, so values such as 00999, 53000 or 99999 passed as Spanish postcodes.

It now checks that prefix, the same way AFFormatter checks Afghanistan's province range. The data provider gains 01001, 28039 and 52001 as valid and 00999, 53000, 99999 as invalid.

Sources:

  • Wikipedia, Postal codes in Spain: "the first two digits, ranging 01 to 52, correspond either to one of the 50 provinces of Spain or to one of the two autonomous cities"
  • Google address data, ES: the per-province prefixes (sub_zips) run from 01 to 52

How this was found: an AI-assisted comparison between this library and the JavaScript library postcode-validator, run over candidate postcodes generated from both rule sets, listed every country where the two disagree. Each disagreement is then checked against postal sources, and the ones where this library is wrong become a PR, one country at a time. Here postcode-validator already requires the 01–52 prefix.

PHPUnit, PHPStan and ECS pass locally.

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.21%. Comparing base (4c9484d) to head (5ef84fa).

Additional details and impacted files
@@            Coverage Diff            @@
##               main      #32   +/-   ##
=========================================
  Coverage     99.21%   99.21%           
- Complexity      503      505    +2     
=========================================
  Files           186      186           
  Lines          1022     1025    +3     
=========================================
+ Hits           1014     1017    +3     
  Misses            8        8           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant