🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

val-zip

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

val-zip

Validate zip codes fast and accurate! A Library of JavaScript Regular Expressions for validating if a specific zip code actually exists in a specific Country.

latest
Source
npmnpm
Version
1.0.13
Version published
Weekly downloads
54
-27.03%
Maintainers
1
Weekly downloads
 
Created
Source

Validate ZIP Codes with Regular Expressions

npm Featured on Openbase

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

Keywords

validation

FAQs

Package last updated on 06 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts