Repository navigation
Accept Nigeria (NG) 11-character postcodes - #75
Conversation
|
@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
left a comment
There was a problem hiding this comment.
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.
# Conflicts: # CHANGELOG.md
|
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 ( |
|
Thank you, @dgilperez, for the quick review and for adding the spaced form yourself. I will keep an eye out for 0.7.0. |
|
It should be live in rubygems now 👌 |
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.