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

PO_BOX_PATTERNSconstant

The regular expressions the PO box parser uses: the box itself, a station after it, a box number first, and a trailing comma.

Import it

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

Definition

const PO_BOX_PATTERNS: { readonly US_PO_BOX: RegExp; readonly STATION_PATTERN: RegExp; readonly LEADING_BOX_NUMBER: RegExp; readonly TRAILING_COMMA: RegExp; } = {
    US_PO_BOX: /^(?:p\.?\s*o\.?\s*box|post\s*office\s*box|pobox|po\s*box)\s*(\d+)\s*,?\s*([^,]+?)\s*,?\s*([A-Za-z]{2})\s*(\d{5}(?:[-\s]?\d{4})?)?\s*$/i,
    STATION_PATTERN: /^(station|stn\.?|succ(?:\.|ursale)?|rpo|rr|r\.r\.)\s+([A-Za-z0-9]+(?:\s*[A-Za-z0-9-]+)*?)(?=\s+[A-Z][a-z]|\s*,|$)/i,
    LEADING_BOX_NUMBER: /^([0-9A-Za-z-]+)\b[,\s]*/,
    TRAILING_COMMA: /,\s*$/,
} as const

Members

NameTypeDescription
US_PO_BOXRegExp
STATION_PATTERNRegExp
LEADING_BOX_NUMBERRegExp
TRAILING_COMMARegExp

Examples

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

console.log(PO_BOX_PATTERNS.US_PO_BOX.exec("PO Box 123, Springfield, IL 62701")?.slice(1));
// → ["123","Springfield","IL","62701"]
[ '123', 'Springfield', 'IL', '62701' ]

What it prints (run when this page was built)

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