Be gentle with your validations
We take the view that users are trying their best. Your validations should be about helping users to give you the right data, not forcing them into lying or accusing them of incompetence.
Create validations that help users
David Hamill has a nice set of guidelines on validating web forms.
The real world is complicated: respect variation
When writing validations, think hard about the real-world range of values and how that might map onto the range that you can deal with in your organisation. Even apparently simple questions like asking for title or gender can be a major issue for some people:
You may be surprised by how difficult an 'ordinary' question can be for some of your users.
Inline validation can help (if done thoughtfully)
One way of helping users through a long or complicated form is to do inline validation: checking each input as the user puts in it. This will add to your programming time, but may make life easier for your users. Before you do it, read:
If you read German, Martin Beschnitt says similar things in his article Optimierung von Webformularen mit Inline-Validierung.
For an illustrated example of how intrusive and annoying inline validations can be, see Bill Scott's post on Inline Form Validation. As I watched the video of his battle to enter a date according to a rigid format, I thought: "Why didn't that programmer work harder on accepting a wider variety of inputs, before fussing with the inline validation?".
Is your validation really necessary?
Jessica Enders analysed the level of errors found in entry of a phone number with no validation, and discovered that almost everyone entered a valid phone number. Putting a validation on this field would have caught few errors, and might have proven a barrier to users who wanted to enter an unusual number such as an international one or one with an extension.
Kabir Bedi suggests that you don't need valildation on optional fields in 10 things that might be wrong with your web forms. "Optional fields in your web forms mean that you don’t mind accepting no response for them. However, when you add validation to it, it just serves to add more friction to the process of completing the forms".
Be gentle with your error messages
No matter how careful you are to avoid errors, people will make mistakes.
Caroline's article on UXmatters.com says how to avoid being embarrased by your error messages.
David Travis on Userfocus talks about communicating errors.
Linda Bustos on Getelastic talks about designing error messages for login forms in her piece: Does your log in make them drop off?
Aartjan van Erkel has similar advice in Dutch: Copywriting-tip 2 voor webformulieren: fluwelen foutmeldingen (Copywriting tip for web forms: gentle error messages).