Code Monkey home page Code Monkey logo

validate-zipcodes's Introduction

Validate ZIP Codes with Regular Expressions

npm

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/[email protected]/dist/va-zip.udm.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!----------------------------------- or -------------------------------------------------->
<script type="module">
 import valZip from "https://cdn.skypack.dev/val-zip@latest";
  //...
</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"; // real, 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

country last update license source
Austria 04.01.2023 none Österreichische Post Aktiengesellschaft
Belgium 21.11.2021 none Bpost
Switzerland 01.01.2023 CC-BY Die Schweizerische Post
Czechia 01.01.2023 none Česká pošta
Germany 01.06.2019 none Launix
Denmark 22.06.2022 none PostNord Danmark
United States 31.12.2020 none Internal Revenue Service, US Census
Norway 01.10.2022 none Osten Norge AS
Finland 30.01.2023 none Posti Group Oy
Italy 26.11.2020 Eurostat free re-use of data Eurostat
Spain 26.11.2020 Eurostat free re-use of data Eurostat
Estonia 05.02.2023 none Republic of Estonia
Iceland 06.02.2023 none Íslandspóstur
France 06.02.2023 Open License v2.0 La Poste Groupe
Luxembourg 06.02.2023 CC-0 Portail 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:

country limitation source
Poland only with permit Poczta Polska Spółka Akcyjna
Sweden paid only Postnummerservice Norden AB
Australia paid only Australia Post

MIT License Copyright (c) 2022-today Leonhard Maier

validate-zipcodes's People

Contributors

memorabilien avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.