1501 East Hennepin Avenue | Minneapolis, MN 55414
| posted on 11/2/09 by Lloyd Dalton and Dave Dohmeier
Validating web page forms is a remarkably difficult task. But if you make websites, you'd better be good at it.
Being good at it means not doing things like this:

That is godawful. It's like vomit on a restaurant floor. Everyone wants to leave.
We've defined some principles for doing better:
Pretty simple, right? Especially because these principles are mostly design-agnostic.
It's NOT simple, though. Meeting each of these principles has a price. Let's take a closer look:
Another security concern is Cross-Site-Scripting (XSS). XSS attacks are made possible when user-supplied data is redisplayed on a page. Repopulating form data does exactly this. Methods of protection against XSS attacks are sanitizing (or filtering) user input, or escaping it upon redisplay. It's best to do both.
Sometimes we think we've done a good job writing good error messages, and we find out from user testing that we're wrong. Communication is hard.
This one is actually fairly easy. It's also an area that touches design a bit — designers need to incorporate error states into their designs, or the user experience will feel disjointed.
This one is a real tradeoff. We're usually pretty strict about email addresses, but quite loose with phone numbers. It often depends on what's being done with the data.
A final note on client-side validation: with the rise of robust javascript libraries, client-side form validation has become easier to do. We've tried it, and we haven't liked the results. There are several drawbacks:
The advantage of client-side validation is speed. Toward that end, we've built a number of forms and components which use AJAX requests to submit form data, saving the browser from reloading and redisplaying the entire page. This gives dramatic speed gains, and will likely become more widespread.
You know how you'll know if your form validation is really good? Because you won't notice it. Noticing form validation (in the form of, "What the what?!") means that the experience was broken in some way.

We're constantly talking to each other about what's new: a project we're working on, a new site we're obsessed with, or some other geekery. We figured, why not share those conversations with you?
Welcome to our collective mind.