SsnFormatUS
The layout of a US Social Security number: bare digits, dashes or spaces.
The same nine digits arrive in three shapes: '123456789' from a database,
'123-45-6789' from a card, '123 45 6789' typed off a paper form. SsnFormatUS
names those shapes, and the SSN methods use it twice — a format parameter says
which layouts to accept, and an output parameter says which shape to return.
The two are independent: you can accept anything and always store bare digits.
Members
| Member | Meaning |
|---|---|
Any |
No constraint. As input: accept every supported layout. As output: return the number in whichever layout it arrived in. This is the default for format. |
Digits |
Nine bare digits, e.g. '123456789' — the shape to store. |
Dashed |
The usual dashed form, e.g. '123-45-6789'. This is the default for output. |
Spaced |
Space-separated groups, as often typed from paper forms, e.g. '123 45 6789'. |
Where it is used
Ssn and Itin on CkUS take both parameters: format
(the layout the input must match, default Any) and output (the shape to return,
default Dashed). SsnMask takes only output — it decides the shape of the masked
value, and with Any a valid value keeps its own layout while the fully masked
placeholder falls back to dashed.
Quick look
use SafeCoder\CommonKit\CkUS;
use SafeCoder\CommonKit\Enums\SsnFormatUS;
CkUS::Ssn('123 45 6789'); // -> '123-45-6789' (any layout in, dashed out — the defaults)
CkUS::Ssn(
input: '123-45-6789',
output: SsnFormatUS::Digits
); // -> '123456789' (the storage shape)
CkUS::Ssn(
input: '123456789',
format: SsnFormatUS::Dashed
); // -> '' (valid number, but only the dashed layout was allowed)
CkUS::SsnMask(
input: '123-45-6789',
output: SsnFormatUS::Spaced
); // -> '*** ** 6789'