Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex for Nicaraguan postal codes is incorrect #131

Closed
nielslange opened this issue Sep 15, 2023 · 2 comments
Closed

Regex for Nicaraguan postal codes is incorrect #131

nielslange opened this issue Sep 15, 2023 · 2 comments

Comments

@nielslange
Copy link

Nicaragua uses the ISO 3166-2 country code NI. The current regex for Nicaraguan postal codes is hosted on this GitHub repository:

/^((\d{4}-)?\d{3}-\d{3}(-\d{1})?)?$/

This pattern successfully validates:

  • An empty string → Entire pattern is optional.
  • 123-456 → Core 3-3 pattern.
  • 1234-123-456 → Optional 4-digit prefix.
  • 123-456-7 → Optional single-digit suffix.
  • 1234-123-456-7 → Includes all optional parts.

However, according to codigo-postal.org and en.youbianku.com, Nicaraguan postal codes consist of 5 digits and never start with 0. grcdi.nl outlines the following specific number ranges for postal codes:

10-16, 21-22, 25-27, 31-32, 34-35, 37-38, 41-48, 51-52, 55-56, 61-62, 65-66, 71-72, 81-82, 91-92

And suggests this regex:

\A((10|11|12|13|14|15|16|21|22|25|26|27|31|32|34|35|37|38|41|42|43|44|45|46|47|48|51|52|55|56|61|62|65|66|71|72|81|82|91|92)\d{3,3})\Z

I recommend updating the Nicaraguan postal code regex for more accurate validation.

@melwynfurtado
Copy link
Owner

melwynfurtado commented Sep 24, 2023

Thanks for researching Nicaraguan postcodes. Can you optimise your regex for the first two digits as I see the first digit can be 1-9 and the second digit 1-8?
Also, please raise a PR. 🙏

Copy link

Stale issue message

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

No branches or pull requests

2 participants