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 · Australian country module

validateAustralianAddressfunction

Checks an Australian address against Australia Post's blocks of postcodes: the postcode is four digits, some state's block holds it, and it is the state named, or one it serves across a border (from the ABS's Postal Areas). Also warns when the state, the postcode or the suburb is missing.

Import it

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

Definition

function validateAustralianAddress(address: ParsedAddress, options?: ValidationOptions): CountryValidation

Parameters

NameTypeDescription
addressParsedAddress

The address as parseAustralianAddress (or parseLocation with the module) returns it.

options (optional)ValidationOptions

strictPostalValidation: true makes the postcode findings errors; the rest are not used.

Returns

CountryValidation

The errors and warnings, each with its field, code and message.

Examples

import { parseAustralianAddress, validateAustralianAddress } from "@johnmorrisdotca/address-plus/au";

const parsedAddress1=parseAustralianAddress("1 Main St, Sydney VIC 2000");
if (!parsedAddress1) throw new Error("The example address did not parse.");
console.log(validateAustralianAddress(parsedAddress1).warnings[0].message);
// → "Postcode 2000 belongs to NSW, not VIC"
Postcode 2000 belongs to NSW, not VIC

What it prints (run when this page was built)

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