CIE AS & A Level Computer Science, section 6.2 (Data integrity)
What validation is
Validation is an automatic check by the computer that data entered is sensible and in the right form. It does not prove the data is correct, only that it is acceptable.
Validation checks
| Check | What it tests | Example |
|---|---|---|
| Range check | the value is between a lower and upper limit | age between 0 and 120 |
| Limit check | the value is above or below one limit | the quantity ordered is at least 1 |
| Format check | the data has the right pattern | a date written DD/MM/YYYY, or a postcode |
| Length check | the data has an allowed number of characters | a password with 8 to 16 characters |
| Presence check | a required field is not empty | a name must be entered |
| Existence check | the value exists in a set of valid values or in another file | a product code that is in the catalogue |
| Check digit | a digit calculated from the other digits is checked to detect typing errors | the last digit of a barcode or ISBN |
Worked example: a check digit
A code has four digits . Multiply each digit by the weights and add:
, so the check digit is and the full code is .
To validate, multiply the five digits by : , and , so the code is valid.
Limits of validation
A value can pass validation and still be wrong. A valid date of birth such as 05/05/2005 might not be the user's real date.
Common mistake: saying validation "makes sure the data is correct". It only checks that the data is reasonable. Also, a range check needs two limits, while a limit check uses only one.
Exam tip: name the check, say what it tests, and give an example using the field in the question (age, postcode, product code). Note that validation cannot prove the data is correct.
Check yourself
Which check makes sure a name has been entered?
A presence check.
What is the difference between a range check and a limit check?
A range check tests that a value lies between two limits; a limit check tests against only one limit.
Why is a check digit used?
To detect errors made when typing or scanning a code.