Programs must not accept nonsense such as an age of 250 or an empty name. Validation checks make the computer reject data that breaks the rules. Verification checks that data was copied in exactly as intended. You need to name, describe and write both.
Validation is an automatic check by the computer that input data is sensible and allowed before it is accepted: range, length, type, presence, format and check digit checks. Verification checks that data has been entered accurately, matching the original: a visual check or a double entry check. Validation cannot prove data is correct, only that it is reasonable.
Type different values into the validation tab of the lab and see which check accepts or rejects each one. Notice that the computer does the checking, with no person involved.
| Check | What it tests | Example |
|---|---|---|
| Range | A value is between a lower and an upper limit | A mark is from 0 to 100 |
| Length | The number of characters is exactly, at least or at most a set number | A password has at least 8 characters |
| Type | The data is the right data type | The number of tickets is an integer, not "two" |
| Presence | Something has been entered; the field is not empty | A surname must be given |
| Format | The data follows a set pattern of characters | A date is DD/MM/YYYY; a code is two letters then four digits |
| Check digit | The final digit, calculated from the others, still matches | The last digit of an ISBN-13 or a barcode |
// range check: keep asking until the value is allowed
REPEAT
OUTPUT "Enter the number of tickets (1 to 6)"
INPUT Tickets
IF Tickets < 1 OR Tickets > 6
THEN
OUTPUT "Error: enter a number from 1 to 6"
ENDIF
UNTIL Tickets >= 1 AND Tickets <= 6
// length check
REPEAT
OUTPUT "Enter a password of at least 8 characters"
INPUT Password
UNTIL LENGTH(Password) >= 8
// presence check
OUTPUT "Enter your surname"
INPUT Surname
WHILE Surname = "" DO
OUTPUT "Surname must not be empty. Enter your surname"
INPUT Surname
ENDWHILE
A range check is about the value (13 is too big); a length check is about the number of characters ("abc" is too short). Name the check that matches the rule in the question.
A check digit is an extra digit worked out from the other digits and added to the end. When the number is entered later, the computer recalculates it; if the result differs, a digit was typed wrongly or two digits were swapped.
A check digit is a validation check (it is calculated automatically), even though it catches typing mistakes. It cannot tell you whether the number is the right book, only that the digits are consistent.
Four quick checks. Each correct answer earns XP and records this skill on your profile.
What is validation?
Which check makes sure a field has not been left empty?
Which of these is a verification check?
In the lab, a range check accepts 1 to 6. Which input is rejected?
Data can pass every validation check and still be wrong: a date of birth of 12/03/2009 typed instead of 21/03/2009 is perfectly sensible. Verification catches mistakes made while copying or typing.
// double entry check
REPEAT
OUTPUT "Enter your new password"
INPUT Password1
OUTPUT "Enter the password again"
INPUT Password2
IF Password1 <> Password2
THEN
OUTPUT "The passwords do not match. Try again"
ENDIF
UNTIL Password1 = Password2
Validation and verification are not interchangeable. Validation: is the data reasonable? Verification: is it the same as the original? Neither guarantees the data is true.
Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.
A product code must be two capital letters followed by four digits, e.g. KT2093. Which check is the most suitable?
Why can validation not guarantee that data is correct?
The first 12 digits of an ISBN-13 give a weighted sum of 120. What is the check digit?
Which pseudocode statement is a length check?
This skill is now recorded on your profile. Keep the chain going.