A mask must not forbid legal format variants
Aliases: over-constrained mask · international phone mask · variant rejection
What it is
A mask accepts characters against one fixed cell map. In life the same field often has several legal variants: a mobile number with or without a country code, cards of 16 or 19 digits, dates as day-month-year. If the map draws only one of those, other legal input is blocked at the key. That is mask over-constraint. It is which shapes are allowed in, not whether hyphens reduce load, and not whether the caret jumps on paste.
Why it happens
A mask’s power is that it refuses every key that does not fit a cell. That helps when the variant set has size one, and becomes false rejection when the set is larger. +86 will not go into an eleven-digit-only trough; US MM/DD will not go into YYYY-MM-DD cells, even if the backend could parse both. Over-constraint pulls semantic validation down to the keystroke layer; legal values never get to assemble. Travelers, immigrants, and holders of foreign-issued cards reliably hit a domestic map. Extensions, switchboard suffixes, and spaces are often treated as illegal too, narrowing further.
Studying it
List legal writings that actually occur in the business (logs, support corrections, international samples). Type or paste each into the mask; record rejection rate and the character index where refusal happens. Factors: whether a country code switches the map, whether a length range is allowed. Outcomes: pass rate of legal variants, failures after the user rewrites. Do not test only the domestic happy path. If the backend parser accepts a wider set than the mask, the gap is the amount of over-constraint.
Where it stops holding
When the product truly serves one region and one numbering plan, a single map is the right constraint and variants are not legal. Payment cards have a few lengths, but each is still strict digit groups; detect the brand and switch the mask rather than abandoning masks. Free text, names, and addresses have no stable map and should not be masked. After a region or language switch, a mask that does not follow will reject yesterday’s legal writing in the same product.
Applying it
- List every legal shape the field must accept; use a fixed mask only when that set has size one.
- When the set is larger, switch maps from a typed prefix (country code, card BIN), or fall back to loose typing plus format-on-blur.
- Log keys the mask refuses and compare with business logs: recurring “illegal” strings that the backend treats as legal mean the map is too tight.
- Verify with international numbers, switchboard extensions, 19-digit cards, and both local and ISO dates. Any string that stalls on the first mismatch—and that the business should accept—is over-constraint.