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
| Name | Type | Description |
|---|---|---|
isValid | boolean | |
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)