JSPM

joi-postalcode

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1446
  • Score
    100M100P100Q109567F
  • License GPL-3.0-or-later

Joi extension for validating postal codes worldwide using postal-codes-js

Package Exports

  • joi-postalcode

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (joi-postalcode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

joi-postalcode

Joi extension for validating postal codes worldwide using postal-codes-js.

Versions

  • Version 1.X is for Joi < v14
  • Version 2.X (latest) is for Joi > v14

How to Use

Get the required packages:

npm install joi joi-postalcode

Create an extended instance of Joi, then specify the 2-letter ISO country code as a parameter to postalCode in your schema:

const Joi = require('joi')
const joiPostalCode = Joi.extend(require('joi-postalcode'))
joiPostalCode.string().postalCode('CA').validate('A1A 1A1') // Canada
joiPostalCode.string().postalCode('').validate('90210') // Default country is US
joiPostalCode.string().postalCode('TR').validate('33150') // Turkey

See List of postal codes for a list of postal code formats and supported countries.