Skip to content

Accept Nigeria (NG) 11-character postcodes - #75

Merged
dgilperez merged 3 commits into
dgilperez:masterfrom
Adeniyikayodee:ng-digital-postcode
Oct 8, 2026
Merged

dgilperez merged 3 commits into
dgilperez:masterfrom
Adeniyikayodee:ng-digital-postcode

Conversation

@Adeniyikayodee

Copy link
Copy Markdown
Contributor

NIPOST launched a new postcode for Nigeria in October 2026. It has 11 characters in five segments, for example EK-01-A03-FK-01: two letters, two digits, three letters or digits, two letters, and two digits. The two numeric segments run from 01 to 99.

The NG rule accepted six digits only, so every new code was invalid. It now accepts both, with the new code written with hyphens, with spaces, or with no separator, in either case.

Format reference: https://docs.postcode.gov.ng/concepts/postcode-format

The specs pass locally, and I added a changelog entry.

@Adeniyikayodee

Copy link
Copy Markdown
Contributor Author

@dgilperez, I would be grateful if you could look at this whenever your time allows. Nigeria launched a new national postcode on 1 October, and the NG rule still accepts only the six-digit code it replaces, so Rails apps using the gem reject every new code. The format and its source are in the description, along with the specs and a changelog entry. I am glad to change anything that would make this easier to merge. Thank you for keeping this gem going, and please take it at your own pace.

@dgilperez dgilperez left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and for linking the NIPOST format page. I checked the regex against that page and your fixtures, and it works: the numeric segments reject 00, the six-digit code still passes, and malformed codes such as EK-1-A03-FK-01 or EK-01-A03-F1-01 are rejected.

One request before merging: please add the spaced form, EK 01 A03 FK 01, to the valid list. NIPOST displays the code that way, so it's probably what people will paste, and no spec covers it yet.

Optional: the regex also accepts mixed separators, such as EK-01A03 FK01. NIPOST's API tolerates that too, so I'm fine leaving it. If you'd rather require the same separator throughout, a backreference does it:

NG: /\A(\d{6}|[A-Z]{2}([- ]?)(0[1-9]|[1-9]\d)\2[A-Z0-9]{3}\2[A-Z]{2}\2(0[1-9]|[1-9]\d))\z/i,

If you go that way, add EK-01A03 FK01 to the invalid list.

@dgilperez
dgilperez merged commit 8b966fd into dgilperez:master Oct 8, 2026
10 checks passed
@dgilperez

Copy link
Copy Markdown
Owner

Merged, thank you @Adeniyikayodee! Nigerian users would have hit this right away, and the PR came with the source and specs, which made it quick to check.

I added the spaced form (EK 01 A03 FK 01) to the specs myself and resolved a changelog conflict with master, so you don't need to do anything. It ships in 0.7.0, which is going out shortly.

@Adeniyikayodee

Copy link
Copy Markdown
Contributor Author

Thank you, @dgilperez, for the quick review and for adding the spaced form yourself. I will keep an eye out for 0.7.0.

@dgilperez

Copy link
Copy Markdown
Owner

It should be live in rubygems now 👌

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.

2 participants