Describe the correction

An error message should explain what to do next. Invalid value tells someone almost nothing. Enter an email address such as name@example.com gives a concrete path forward. Keep the language tied to the field and the real requirement, without blaming the user or inventing restrictions that the application does not actually enforce.

Start with HTML constraints

Required fields, appropriate input types and sensible numeric limits can prevent straightforward mistakes. The browser’s constraint validation is a useful baseline. Custom validation should address actual application rules or improve the message experience. A decorative JavaScript layer that duplicates native checks can introduce inconsistent states unless both systems are deliberately coordinated.

Choose when to interrupt

A form that reports errors after every keystroke can be exhausting. A reasonable pattern is to validate on submission, then update a field’s existing error as the user corrects it. For example, do not call an unfinished email invalid while the person is still typing its domain unless there is a clear usability reason.

Connect feedback to the field

Give each message an id and reference it from the relevant control with aria-describedby. Set aria-invalid when the value has failed validation. Preserve visible text alongside any color or icon, because a red border is not a complete explanation. If an error disappears, update its associated state and description rather than leaving stale announcements behind.

Handle multiple errors coherently

For a longer form, a summary near the top can list the fields that need attention and link to them. Move focus deliberately after a failed submission so the reader can discover that summary. Keep entered values in place. Requiring someone to reconstruct an entire project inquiry after one invalid field turns a small mistake into unnecessary work.

Verify the recovery journey

Submit an empty form, then one with a malformed email, then a valid example. Check that the first error is discoverable with a keyboard and that correcting it clears the message. Client-side validation is still a convenience, not a security boundary: any server receiving submissions must validate its input independently.

Further reading

Put the idea to work.

Explore free browser tools for images, text and developer workflows.

Try a free tool