Laws / Expectations
Postel's law
The robustness principle
Be liberal in what you accept, and conservative in what you send.
Why it matters
People type phone numbers, dates and names in many formats. Rejecting reasonable input is the interface's failure, not theirs.
Rules to follow
- Accept any reasonable format (spaces, dashes, brackets, country codes) and normalise it yourself.
- Trim whitespace and ignore case where case doesn't matter (emails, codes).
- Validate on blur or submit, not on every keystroke, and explain exactly what to change.
- Show the normalised result back to the person in one consistent format.
- Use the right input type and inputMode so the correct keyboard appears.