Topic 7 · Algorithm design and problem-solving
Validation and verification
▶ Watch the video lessonShort, exam-focused explanation of this topic on the CS with Aamir YouTube channel.When data is entered into a computer system, two kinds of checks help keep it accurate. Validation checks that the data is reasonable and sensible. Verification checks that the data has been entered or copied exactly as it was in the original.
Validation checks
Validation is an automatic check carried out by the program. It can reject impossible data, but it cannot tell whether data is actually correct – a sensible but wrong date of birth will still pass.
| Check | What it does | Example |
|---|---|---|
| Range check | Checks the value is between a lower and an upper limit | A mark must be from 0 to 100 |
| Length check | Checks the number of characters is exact or within limits | A password must have at least 8 characters |
| Type check | Checks the data is the correct data type | Age must be a whole number |
| Presence check | Checks that the field has not been left empty | An email address must be entered |
| Format check | Checks the data follows a set pattern | A student ID must be two letters followed by four digits |
| Check digit | A final digit calculated from the other digits, used to find errors in numbers | The last digit of an ISBN or a barcode |
Pseudocode example: a range check
REPEAT
OUTPUT "Enter a mark from 0 to 100"
INPUT Mark
IF Mark < 0 OR Mark > 100
THEN
OUTPUT "Invalid mark, please try again"
ENDIF
UNTIL Mark >= 0 AND Mark <= 100
The loop keeps asking until the mark is within the range, so invalid data can never be stored.
Verification methods
- Double entry: the data is entered twice and the computer compares the two entries. If they don't match, the user is asked to enter it again – for example, typing a new password twice.
- Visual check (screen check): the user reads the data on the screen and compares it with the original document before confirming it.
Test data
To test that a validation routine works, use four types of test data. For a mark that must be from 0 to 100:
| Type | Meaning | Example |
|---|---|---|
| Normal | Data that should be accepted | 45 |
| Abnormal (erroneous) | Data that should be rejected | -12, 150, "ten" |
| Extreme | The largest and smallest values that should be accepted | 0 and 100 |
| Boundary | A value at the limit that is accepted, and the value just outside it that is rejected | 0 and 100 (accepted); -1 and 101 (rejected) |
Exam tips
- Validation checks data is reasonable; verification checks it matches the original. Never mix them up.
- When asked for a validation check, give the name of the check and how it applies to the data in the question.
- Remember: validation cannot prove that data is correct, only that it is sensible.
Want the full topic notes, slides and worksheets? See Notes & Slides, practise with the free CS with Aamir Quiz App, or order the O Level Computer Science Study Guide.