[go: nahoru, domu]

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

Dutch (NL) postal code regex matches invalid values #208

Open
roelofr opened this issue Jan 31, 2021 · 2 comments
Open

Dutch (NL) postal code regex matches invalid values #208

roelofr opened this issue Jan 31, 2021 · 2 comments

Comments

@roelofr
Copy link
roelofr commented Jan 31, 2021

Hello there,

Following a discussion at work, I looked into a package used for postal code validation (axlon/postal-code-validation), which is seeding data from the Google Address Data Service (as pointed out in axlon/postal-code-validation#27).

After a short discussion, @wotta pointed out that the regex used is invalid. The regex (\d{4} ?[A-Z]{2}) allows the following invalid postal codes:

  • 0123 AB, which are invalid since all our postal codes start with 1-9.
  • 1111 SA, 1111 SD and 1111 SS, which are banned due to the SA, SD, and SS abbreviations which were used in the Second World War source.

A better regex for Dutch postal codes would be [1-9]\d{3} ?(?!SA|SD|SS)[A-Z]{2}, which explicitly excludes zero-based postal codes and invalid suffixes.

I made some tests on regex101.com (click on "Unit Tests" in the left sidebar).

@roelofr roelofr changed the title [NL] Dutch postal code regex is invalid Dutch (NL) postal code regex is invalid Jan 31, 2021
@roelofr roelofr changed the title Dutch (NL) postal code regex is invalid Dutch (NL) postal code regex matches invalid values Jan 31, 2021
@bojanz
Copy link
bojanz commented Mar 6, 2023

Note to Go implementors: [1-9]\d{3} ?(?!SA|SD|SS)[A-Z]{2} has unsupported syntax, regexp.Compile gives: Invalid or unsupported Perl syntax: (?!.

@roubert
Copy link
Member
roubert commented Mar 6, 2023

(?! is the Perl syntax for a zero-width negative lookahead assertion.

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

No branches or pull requests

3 participants