ZipFormatUS
The layouts a US ZIP code can take: five digits, hyphenated ZIP+4, or bare nine digits.
A US ZIP code has two lengths. The short form is five digits: "90210". The long
form, called ZIP+4, adds four more digits that pin the address down to a block or a
building — and those nine digits sometimes arrive hyphenated ("90210-1234") and
sometimes as one unbroken run ("902101234"). ZipFormatUS names these layouts so
you can tell the reader which one your data must match — or say Any and take
whatever arrives.
Members
| Member | Meaning |
|---|---|
Any |
No constraint: every supported layout passes. A five-digit code comes back as five digits, a ZIP+4 comes back hyphenated. This is the default. |
Five |
The five-digit form, e.g. "90210". |
Plus4 |
The hyphenated ZIP+4 form, e.g. "90210-1234". |
Plus4Digits |
The unseparated nine-digit ZIP+4, e.g. "902101234". Accepted on input only — the returned value is always hyphenated. |
Where it is used
One method takes it: Zip on CkUS, through its format
parameter. The format constrains — it never converts. A five-digit code cannot gain
a +4 segment, and dropping one would lose data; a value in the wrong layout is
simply rejected. The one rewrite is the hyphen: the bare nine-digit form is
returned hyphenated, so every code has a single canonical spelling.
Quick look
using SafeCoder.CommonKit;
using SafeCoder.CommonKit.Enums;
CkUS.Zip("90210-1234"); // -> "90210-1234" (Any is the default: every layout passes)
CkUS.Zip(
input: "90210-1234",
format: ZipFormatUS.Five
); // -> "" (not five digits: rejected, empty out)
CkUS.Zip(
input: "902101234",
format: ZipFormatUS.Plus4Digits
); // -> "90210-1234" (nine bare digits in, hyphenated out)