Simple Data Validation Rules That Catch Errors Early
Use required fields, ranges, allowed values, and cross-field checks.
Validation works best when a rule matches a field’s meaning. A correctly formatted value can still be false or belong to the wrong person.
Mark required fields
Decide which values may be blank and distinguish unknown from not applicable where it matters. Make error messages specific.
Set sensible ranges
Use domain-based limits rather than arbitrary numbers. Controlled lists can prevent the same category being entered in several inconsistent ways.
Check relationships
A start date should not normally follow an end date, and line totals should match quantity times price. Test boundary cases and preserve valid input after an error.
Before relying on the result, test a small example, keep an original copy when a file or value is transformed, and check the output in the application where you plan to use it. Browse the tools directory for a utility that matches your task, and use the other practical guides for related checks.
Editorial note: This guide provides general educational information. Follow the requirements of the software, service, or organization involved when a task has specific rules.