Skip to content
Web Design & Development

How to Get Input Validation Right

Checking that data received from users and other systems has the expected type, format and range before it is used or stored.

MediaScaleUp Editorial Team 2 min read 10 views
How to Get Input Validation Right

What is at stake

Validation stops bad data and many attacks at the edge of the application, and server-side validation is required even when browsers validate forms.

The playbook

  1. Validate every input on the server
  2. Use framework validation rules
  3. Constrain lengths, types and formats
  4. Return clear, specific error messages
  5. Validate data from third-party APIs too

Where it goes wrong

Avoid:

  • Relying on HTML attributes alone
  • Blocklists of forbidden characters
  • Silently changing user input
  • Trusting hidden form fields
What to do and what to avoid with input validation, side by side
Good practice against the usual mistakes, from the sources listed below.

The numbers behind it

Published figures for Input Validation
MeasureFigure
Server-side validationrequired, since client-side checks can be bypassed
Allowlist approachdefine what is valid rather than trying to list everything invalid
Syntactic and semanticcheck format and business meaning
Relationship to encodingvalidation does not replace output encoding

Getting outside help

When to hand it over: Bring in help when forms accept malformed data, or when integrating with external data sources.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Web Design & Development