Here I was trying to enter my new zip code. When clicking ‘confirm’ the website informed me that this was an invalid zip code. The error message (in Dutch) says:
The zip code must contain 4 digits and two characters.
Hey, my zip code does have 4 digits and two characters. Why is this not being accepted? Well, because of the space between the digits and the characters.
Every time I see this kind of behaviour, I’m thinking of the Robustness principle.
Be conservative in what you send; be liberal in what you accept.
The programmer had several options:
- Create two input boxes (one for the digits, one for the characters) so I had visual feedback that they expected me to separate the digits and the characters.
- Write some client side scripting that disregarded any spaces I might enter.
- Actually try to parse my input before throwing their hands in the air and crying: “I give up! Will those users never learn!”.
So, next time you write some validation code (for dates, names, zip codes, whatever), think of the user and try to do your best to parse the input of the user before giving up.
(One of the reasons I like Remember The Milk so much is because they support a large number of input formats).