validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

fix(isPostalCode): Improve Dutch postal code regex

Open RobinvanderVliet opened this issue 1 year ago • 7 comments

I have improved the regular expression for postal codes of the Netherlands. They cannot start with a zero, and they cannot contain "SA", "SD" and "SS".

More information: https://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands

RobinvanderVliet avatar Aug 21 '23 17:08 RobinvanderVliet

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.95%. Comparing base (b958bd7) to head (f0856e7). Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2271   +/-   ##
=======================================
  Coverage   99.95%   99.95%           
=======================================
  Files         107      107           
  Lines        2454     2454           
  Branches      619      619           
=======================================
  Hits         2453     2453           
  Partials        1        1           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 21 '23 17:08 codecov[bot]

Is there maybe a link by PostNL (the national postal carrier) that explains these rules that we can use as a source?

WikiRik avatar Aug 21 '23 17:08 WikiRik

Is there maybe a link by PostNL (the national postal carrier) that explains these rules that we can use as a source?

I checked their website, and I cannot find anything on there that explains it. There are plenty of other resources on the web that explain the rules.

If you search "postcodekaart" (postal code map), you will see lots of maps. You can easily notice they never start with zero.

The letter combinations "SA", "SD" and "SS" are avoided because of their associations with the Nazi occupation.

RobinvanderVliet avatar Aug 21 '23 20:08 RobinvanderVliet

Yeah, I've seen these changes in various other maps but I was hoping for some better source. I'll try to search for them in the coming days before approving this PR, since I do think these changes are correct

WikiRik avatar Aug 21 '23 21:08 WikiRik

I found more maps and lists, but couldn't really find a (semi-)official source unfortunately. Others suggest this regex (or similar ones) as well for Dutch postal codes

I came across an official source containing the same regular expression: https://tracking.postnl.nl/track-and-trace/api/trackAndTrace/countries

Dutch postal code regular experssion

RobinvanderVliet avatar Dec 03 '23 11:12 RobinvanderVliet

Ah nice, and I see they have different countries as well. Could you add those in a separate PR?

WikiRik avatar Dec 03 '23 15:12 WikiRik

Ah nice, and I see they have different countries as well. Could you add those in a separate PR?

PostNL provides 20 regular expressions in total. I've compared the rest to those that we already have in validator.js, and ours are the same or more specific.

RobinvanderVliet avatar Dec 03 '23 19:12 RobinvanderVliet

Is there anything else that needs to be done before this pull request can be merged? Let me know if there's anything I can do to help.

RobinvanderVliet avatar Mar 16 '24 12:03 RobinvanderVliet