Effortless Zip Code Checks With val-zip JavaScript Library

Category: Javascript | September 13, 2023
Views Total:24 views
Official Page:Go to website
Last Update:September 13, 2023


Effortless Zip Code Checks With val-zip JavaScript Library


val-zip is a handy JavaScript utility for validating zip codes based on country. It contains predefined regular expressions for validating zip codes from various countries.

How to use it:

1. Install and import the val-zip.

$ npm i val-zip
// ES Module
import valZip from "val-zip";
// Node.js
const valZip = require("val-zip");
// Browser
<script type="module" src="/dist/va-zip.udm.js" ></script>
// Or
<script type="module">
  import valZip from "https://cdn.skypack.dev/val-zip@latest";

2. Pass a country code and zip code string to the valZip function, and it will return true or false if the zip code is valid or not. Supported countries:

  • Austria
  • Belgium
  • Switzerland
  • Czechia
  • Germany
  • Denmark
  • United States
  • Norway
  • Finland
  • Italy
  • Spain
  • Estonia
  • Iceland
  • France
  • Luxembourg
// ISO 3166 Country Code
var userCountry = "US";
// zip code
var inputZip = "12345";
// returns false
valZip(inputZip, userCountry);

You Might Be Interested In:

Leave a Reply