Input Validation
Checking input at the right moment, which is rarely while the user is still typing.
Definition
Validation verifies that input meets requirements. The design decisions are when to validate, where to show the result, and how much to accept before rejecting.
Expert heuristic. A review criterion developed by practitioners. Useful and widely taught, but evaluated by judgement rather than measurement.
On this plate
Reach for this when
- Designing any form.
- Reviewing form abandonment.
- A form is rejecting submissions and nobody can say at which field people give up.
Common mistakes
- Validating before the user has finished.
- Errors far from their cause.
- Over-strict format rules.
- Data lost on failure.
When to validate
| Timing | Use for | Avoid for |
|---|---|---|
| On input, as they type | Positive confirmation, password strength, character counters | Negative judgements before the field is finished. |
| On blur | Format checks, most field validation | Fields the user has not yet visited. |
| On submit | Cross-field rules, server-side checks | Anything that could have been caught earlier. |
| After first failure | Re-validating on input so the error clears as it is fixed | The first pass, which should wait for blur. |
Requirements for an accessible validation experience
- State requirements before the field is filled, not only after failure.
- Show the message adjacent to the field, associated with aria-describedby.
- Mark the field with aria-invalid when it fails.
- Summarise all errors at the top on submit, with links to each field, and move focus to the summary.
- Never clear entered data on a validation error.
- Accept broadly and normalise, rather than rejecting formats a reasonable person would type.
Timing by field type
The timing table above is the general rule. This is how it lands on the fields that come up in almost every product.
| Field | Validate | Why |
|---|---|---|
| Email, phone, postcode | On blur | Format is only knowable once they have finished |
| Password being created | As they type, positively | The rules are a checklist they are working through |
| Username availability | On blur, then confirm | It needs a request, and mid-typing is noise |
| Numeric range | On blur, and again on submit | Partial numbers are not errors |
| Required, left empty | On submit only | An untouched field is not a mistake yet |
| Anything the server decides | On submit | The client cannot know, so do not pretend |
Messages that fix the problem
Do
- Say what is wrong and what to do: Enter an expiry date in the future, not Invalid date.
- Accept what people type and normalise it: spaces in card numbers, brackets in phone numbers, any reasonable date order you can disambiguate.
- Show the rule before the field is filled, where the rule is not obvious.
- Keep the message beside the field, and keep it there until the field is corrected.
Do not
- Reject a format you could have parsed. Postel's law is doing real work in forms.
- Use colour alone to mark a failing field.
- Wipe the field, or the whole form, on failure.
- Validate a field the reader has not visited yet, which is telling them off for not having got there.
One field, three moments
In practice
- i.
Error summary with focus movement
Long formsThe pattern used in government service design: a summary at the top listing every problem, each linking to its field, with focus moved to the summary on submit. It works for keyboard and screen reader users and for everyone else.
- ii.
Invalid at the first character
Premature validationAn email field marked invalid after the first letter is telling the reader they are wrong for having started. Validation before the reader has finished is an interruption, not help.
Local chart
PAT·007 · Region III · Grid E2
This entry and the entries it is stated to connect with. Each line is labelled with what the connection means.
Sources
Where a source establishes something narrower than the popular reading of it, the note says so.
- [1]
Continue from here
Each link says what the connection is, so you can tell a principle from an alternative from a thing people mix this up with.
Applies when you are designing
Principles behind this
The reasoning this solution is an application of.
- Error PreventionHEUR·005 · Heuristic
- Help Users Recognise, Diagnose and Recover From ErrorsHEUR·009 · Heuristic
- Postel's LawLAW·012 · Law
- ConstraintsPRIN·009 · Principle
Depends on
Get these right first, or this one will not hold.
- Error Identification and SuggestionA11Y·016 · Accessibility
- Focus ManagementA11Y·004 · Accessibility
- Labels and InstructionsA11Y·017 · Accessibility
- Error MessagesWRT·002 · UX writing
Detecting the problem is half the job. The sentence is the other half.
Often used with
These usually appear in the same screen or the same decision.
- Date PickerCMP·009 · Component
- StepperCMP·029 · Component
- Text InputCMP·003 · Component
- AuthenticationPAT·023 · Pattern
- Autocomplete and TypeaheadPAT·003 · Pattern
- Multi-Step FlowsPAT·016 · Pattern
- Payments and CheckoutPAT·024 · Pattern
Practical example
A worked decision where this was the deciding factor.
- One Long Form or Several Short StepsCASE·009 · Case study
Check your work
Review passes that test whether this was done properly.
- Form UX ChecklistCHK·001 · Checklist
Related concept
Connected closely enough to change how you apply this.
- Form Labels and Help TextWRT·009 · UX writing