
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 $ 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";
</script>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);






