Validation – How far would you go?
I recently read a discussion on validation of user inputs. The example used was of validating the Date of Birth a.k.a DOB field. The programmer was adventurous and wanted to put validation such as
- If DOB is more than 120 years ago, message: “You cannot be that old!!!”
- If DOB is in the future, message: “You must be kidding, you are not born yet!!!”
His basic question was on how far would you go in validating a user input?
My view is to put minimum validation at the field level. For this example the developer can check whether it is valid date or not but that’s it!!
One can always put all the necessary validation at the form level. By doing this, most of the business logic is at one place & not divided across various fields.
Also, avoid showing ugly error messages while the user is typing. If the validation is to be done at the field level then provide hints / suggestions to the user by showing text next to his input.
We always want correct and valid data in our databases but at the same time we should not act like a policeman slapping the user for every mistake he/she makes.
So, in your next project, how far would you go in validating user inputs?