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

validateAddressfunction

Checks an address: whether it has what an address needs, whether its ZIP or postal code is well formed and belongs to the state, province or prefecture named, and how sure the parser is. With country modules in options.countries, an Australian or British address is checked by its module's validator.

Import it

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

Definition

function validateAddress(addressString: string, options?: ValidationOptions): AddressValidationResult

Parameters

NameTypeDescription
addressStringstring

The address as one string.

options (optional)ValidationOptions

What to require and how strict to be (see ValidationOptions).

Returns

AddressValidationResult

Whether it is valid, the confidence and completeness from 0 to 1, every error and warning with its code, suggestions, and the parsed address (null when it could not be parsed).

Examples

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

console.log(validateAddress("123 Main St, Seattle, NY 98101").warnings[0].code);
// → "POSTAL_REGION_MISMATCH"
POSTAL_REGION_MISMATCH

What it prints (run when this page was built)

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