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

PostalValidationResulttype

What validatePostalCode returns: whether the code is well formed, its type, and the code written the standard way.

Import it

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

Definition

interface PostalValidationResult {
    isValid: boolean;
    type: "zip" | "postal" | null;
    formatted?: string;
    message?: string;
}

Members

NameTypeDescription
isValidboolean
type"zip" | "postal" | null
formatted (optional)string | undefined
message (optional)string | undefined

Examples

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

console.log(validatePostalCode("98101"));
// → {"isValid":true,"type":"zip","formatted":"98101","message":"Valid US ZIP code format"}
{
  isValid: true,
  type: 'zip',
  formatted: '98101',
  message: 'Valid US ZIP 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.