1.0.13 • Published 1 year ago

val-zip v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Validate ZIP Codes with Regular Expressions

npm Featured on Openbase npm.io

A Library of JavaScript Regular Expressions for validating if a specific Zip-code exists in a specific Country.

Not every 5 digit number is automatically a zip code... As of now Regular Expression seem to be the fastest way of validating if a zip code actually exists. No slow backend validation needed, just some fancy RegExp.

So Why val-zip? Because it is free for commercial use and it is super fast and light weight with only 448kB size.

img

As of now the Regular Expressions for Germany, Austria, Switzerland, USA (5-Digit version), Belgium, Denmark, Czechia, Finland, Norway, Italy, Spain, Estonia, Iceland, France, Luxembourg are available with more coming asap.

Usage

Download via Node Package Manager (NPM):

npm install val-zip

Import via Content Delivery Network (CDN):

<script type="module" src="https://cdn.skypack.dev/val-zip@latest" corossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/val-zip@latest/dist/val-zip.umd.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="module" src="https://unpkg.com/val-zip@1.0.12/dist/va-zip.udm.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Note: CDN is still wip, so error may occur. In doubt use skypack cdn

Example

import valZip from "val-zip"; // make sure to use type="module" or the ".mjs" file extension
// alternative: const valZip = require("val-zip"); 
// note: the require function is nodejs specific and is not available in a ESM or Browser environment.
// make sure to use type="commonjs" or the ".cjs" file extension

// let's say a random user puts in a zipcode somehow and you want to validate if the zip code exists.

var userCountry = "US"; //  ISO 3166 Country Code; string
var inputZip_1 = "12345"; // fake, this zipcode does NOT exist in the United States 
var inputZip_2 = "00601"; // reak, exists


valZip(inputZip_1, userCountry) // returns false
valZip(inputZip_2, userCountry) // returns true

Zip Code Sources

Note: All data is heavily modified and does not resemble the original data base at all

countrylast updatelicensesource
Austria04.01.2023noneÖsterreichische Post Aktiengesellschaft
Belgium21.11.2021noneBpost
Switzerland01.01.2023CC-BYDie Schweizerische Post
Czechia01.01.2023noneČeská pošta
Germany01.06.2019noneLaunix
Denmark22.06.2022nonePostNord Danmark
United States31.12.2020noneInternal Revenue Service, US Census
Norway01.10.2022noneOsten Norge AS
Finland30.01.2023nonePosti Group Oy
Italy26.11.2020Eurostat free re-use of dataEurostat
Spain26.11.2020Eurostat free re-use of dataEurostat
Estonia05.02.2023noneRepublic of Estonia
Iceland06.02.2023noneÍslandspóstur
France06.02.2023Open License v2.0La Poste Groupe
Luxembourg06.02.2023CC-0Portail Open Data

Some Countries are missing, just because the official zipcode database is either paywalled or entirely copyrighted.

This is the List of countries I am unable to source data from:

countrylimitationsource
Polandonly with permitPoczta Polska Spółka Akcyjna
Swedenpaid onlyPostnummerservice Norden AB
Australiapaid onlyAustralia Post

MIT License Copyright (c) 2022-today Leonhard Maier

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago