Skip to the content

address-plusアドレスプラス

Parse, validate, format and compare addresses locally, add country modules and mount an optional native form field.

address-plus extends the parse-address style with typed results, validation, formatting and country modules. About the name

Contents

Reference · Parsing, formatting and shared types

validatePostalCodefunction

Checks the shape of a US ZIP code or a Canadian postal code.

Import it

import { validatePostalCode } from "@johnmorrisdotca/address-plus";

Definition

function validatePostalCode(code: string): PostalValidationResult

Parameters

NameTypeDescription
codestring

The code, with or without the space or the ZIP+4.

Returns

PostalValidationResult

Whether it is well formed, its type (zip or postal), and the code written the standard way.

Examples

import { validatePostalCode } from "@johnmorrisdotca/address-plus";

console.log(validatePostalCode("k1a0b1"));
// → {"isValid":true,"type":"postal","formatted":"K1A 0B1","message":"Valid Canadian postal code format"}
{
  isValid: true,
  type: 'postal',
  formatted: 'K1A 0B1',
  message: 'Valid Canadian postal code format'
}

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/address-plus 1.7.0.