🎯 Syllabus & Goals 3 min
Cambridge 7.5 · Validation and verification Paper 2 · Algorithms, Programming and Logic
By the end of this lesson you can:
- Explain the difference between validation and verification, and why both are needed.
- Describe and write pseudocode for range, length, type, presence and format checks, and describe a check digit.
- Describe the verification methods double entry and screen/visual check, and choose suitable checks for given data.
Textbook: Chapter 7, §7.5 (pp. 276–281)
Recap / Warm-Up 5 min
You can now loop until a condition is met. That is exactly how a program refuses bad data: it keeps asking until the input passes a check.
Quick starter
A form accepts the date of birth 31/02/2010. What is wrong, and should a computer be able to spot it?
Reveal the answer
February never has 31 days. Yes — a program can check this automatically. That automatic check is validation.
🧠 Key Concept 14 min
1 · Two checks with similar names
2 · The six validation checks
| Check | What it checks | Example |
|---|---|---|
| Range | a number is between a lower and an upper value | a percentage is 0 to 100 |
| Length | data has an exact number of characters, or a number between two limits | a PIN has exactly 4 digits; a family name has 2–30 characters |
| Type | data is of the right data type | number of siblings is an integer |
| Presence | data has been entered — not left blank | email address on an online order |
| Format | characters follow a pre-defined pattern | a room code like B204: one letter, three digits |
| Check digit | the final digit, calculated from the others, is correct | barcodes, ISBNs, vehicle identification numbers |
Each check is a loop that repeats until the data passes. Two examples:
Range check (0–100)
OUTPUT "Enter the mark "
REPEAT
INPUT Mark
IF Mark < 0 OR Mark > 100
THEN
OUTPUT "Mark must be 0 to 100, re-enter "
ENDIF
UNTIL Mark >= 0 AND Mark <= 100Length check (8–12 characters)
OUTPUT "Choose a password "
REPEAT
INPUT Password
IF LENGTH(Password) < 8 OR LENGTH(Password) > 12
THEN
OUTPUT "8 to 12 characters, re-enter "
ENDIF
UNTIL LENGTH(Password) >= 8 AND LENGTH(Password) <= 12Type check (whole number)
OUTPUT "How many siblings? "
REPEAT
INPUT Siblings
IF Siblings <> DIV(Siblings, 1)
THEN
OUTPUT "Whole number only, re-enter "
ENDIF
UNTIL Siblings = DIV(Siblings, 1)Presence check
OUTPUT "Enter your email address "
REPEAT
INPUT Email
IF Email = ""
THEN
OUTPUT "*=Required "
ENDIF
UNTIL Email <> ""Format check — a room code such as B204 (one capital letter, then three digits)
REPEAT
OUTPUT "Room code (e.g. B204) "
INPUT RoomCode
Valid ← FALSE
IF LENGTH(RoomCode) = 4
THEN
IF SUBSTRING(RoomCode, 1, 1) >= "A" AND SUBSTRING(RoomCode, 1, 1) <= "Z"
THEN
Valid ← TRUE
ENDIF
ENDIF
UNTIL Valid(A full format check also tests that characters 2–4 are digits, in the same way. String handling is taught in Unit 8.)
3 · Check digits
A check digit is the final digit of a code, calculated from all the other digits. When the code is typed or scanned, the computer recalculates it. If the result does not match, the code is rejected. It detects:
- an incorrect digit — 5327 entered instead of 5307;
- a transposition error — two digits swapped: 5037 instead of 5307;
- omitted or extra digits — 537 or 53107 instead of 5307;
- phonetic errors — 13 (thirteen) heard instead of 30 (thirty).
4 · Verification: double entry and visual check
A screen/visual check is manual. When entry is complete, the data is shown on screen and the user confirms it is correct — either by comparing with the paper form, or from their own knowledge.
Worked Example 12 min
Worked example 1 · Choosing checks for an online form
A youth club's online sign-up form asks for four items. Choose validation and verification for each.
| Data item | Validation (with reason) | Verification |
|---|---|---|
| Family name | presence (must not be blank); length 2–30 (real names fit this) | visual check on the summary screen |
| Age | type — integer; range 11–18 (the club's age limits) | visual check |
| Password | length 8–12; presence | double entry — the user cannot see the hidden characters |
| Phone number | type — digits only; length (e.g. 10–15 digits) | double entry or visual check |
- Ask "what could be impossible?" — blank, too long, wrong type, out of range. Each answer names a validation check.
- Ask "what could be mistyped but still look valid?" — that needs verification.a mistyped password is valid but unknown to the user, so they could never log in.
- Give a reason tied to the data, e.g. "range 11–18 because the club only takes those ages"."with reasons" questions give a mark for the reason, not just the check.
Worked example 2 · Presence, type and range in one loop
A cinema app lets a user book 1 to 6 tickets. The input must not be blank, must be a whole number, and must be in range.
REPEAT
OUTPUT "Tickets (1-6): "
INPUT Entry
Valid ← FALSE
IF Entry = ""
THEN
OUTPUT "Required"
ELSE
IF Entry <> DIV(Entry, 1)
THEN
OUTPUT "Whole number please"
ELSE
IF Entry < 1 OR Entry > 6
THEN
OUTPUT "1 to 6 only"
ELSE
Valid ← TRUE
ENDIF
ENDIF
ENDIF
UNTIL Validvalid = False while not valid: entry = input("Tickets (1-6): ") if entry == "": print("Required") elif not entry.isdigit(): print("Whole number please") elif int(entry) < 1 or int(entry) > 6: print("1 to 6 only") else: valid = True tickets = int(entry) print("Booked", tickets, "tickets")
Tickets (1-6): Required Tickets (1-6): 2.5 Whole number please Tickets (1-6): 9 1 to 6 only Tickets (1-6): 4 Booked 4 tickets
- Presence first. A blank entry cannot be tested for type or range.the checks are nested so each runs only if the one before it passed.
- Then type — 2.5 is rejected as not a whole number.
- Then range — 9 is rejected.
- Each rejection outputs why, then the loop asks again. 4 passes all three, so
Validbecomes TRUE.
Worked example 3 · Checking an ISBN-13 check digit
A librarian types the ISBN 978-1-91502-463-? . Calculate the check digit (the 13th digit).
| Digit | 9 | 7 | 8 | 1 | 9 | 1 | 5 | 0 | 2 | 4 | 6 | 3 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Weight | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 | 1 | 3 |
| Product | 9 | 21 | 8 | 3 | 9 | 3 | 5 | 0 | 2 | 12 | 6 | 9 |
- Multiply the 12 digits by 1, 3, 1, 3, … in turn (the weights).
- Add the products: 9 + 21 + 8 + 3 + 9 + 3 + 5 + 0 + 2 + 12 + 6 + 9 = 87.
- Find the remainder ÷ 10: 87 MOD 10 = 7.
- Subtract from 10: 10 − 7 = 3 (if the remainder is 0, the check digit is 0). Full ISBN: 978-1-91502-463-3.
- Test a transposition: typing …9510… instead of …9150… gives a total of 95 and a check digit of 5, not 3 — so the error is detected.the weights 1 and 3 make swapped neighbours change the total.
Try It Yourself 12 min
Goal: Name the validation check needed for: (a) a month number 1–12; (b) a postcode that must not be empty; (c) a 6-digit PIN; (d) a quantity that must be a whole number.
Goal: Write pseudocode to check that a child can go on a ride: the age must be over 7 and under 12, and the height over 110 cm and under 150 cm. Re-ask for each value until it is valid.
Goal: Explain why a part number in the form XXX999 (three letters, three digits) needs both validation and verification. Suggest one error that validation would miss.
Hint
A format check confirms "three letters then three digits". But ABC123 typed as ABC132 still fits the format. Which method would spot that?
📝 Exam Practice 10 min
Explain what is meant by validation and verification.
Mark scheme
- Validation: an automatic check by the program / computer (1)…
- …that data is reasonable / sensible / within set rules before it is accepted (1).
- Verification: checking that data has been copied / entered accurately (1)…
- …e.g. by double entry or a visual check against the original (1).
A website stores a contributor's email address and password. For each item, describe one validation check and one verification method that could be used.
Mark scheme
- Email validation: presence check — must not be blank (1); format check — contains one @ and a full stop after it (1).
- Email verification: double entry — typed twice and compared (1).
- Password validation: length check, e.g. 8–12 characters (1); (or format check — must contain a digit) (1).
- Password verification: double entry, because it is hidden on screen (1).
- Max 6.
Write pseudocode to input a score and use a range check so that only values from 0 to 50 are accepted. Output a message for any rejected value.
Mark scheme
- A loop that repeats input, e.g.
REPEAT … INPUT Score … UNTIL(1) - Correct rejection test, e.g.
IF Score < 0 OR Score > 50(1) - Error message output for a rejected value (1)
- Correct exit condition, e.g.
UNTIL Score >= 0 AND Score <= 50(1)
Identify three types of error that a check digit can detect.
Mark scheme
- An incorrect digit (1)
- Transposition — two digits swapped (1)
- Omitted or extra digits (1)
- Phonetic errors, e.g. 13 for 30 (1). Max 3.
🗝️ Recap & Key Terms 3 min
Validation lets a program reject unreasonable data automatically. Verification checks data was copied accurately. Good systems use several validation checks on one item, plus double entry or a visual check.
- Validation
- Automated checks by a program that data is reasonable before it is accepted into a computer system.
- Verification
- Checking that data has been accurately copied from another source or transferred within a system.
- Range check
- Checks that a number is between an upper and a lower value.
- Length check
- Checks that data is an exact number of characters, or between two lengths.
- Type check / presence check
- Checks that data is of a given data type / that a data item has been entered.
- Format check
- Checks that the characters entered conform to a pre-defined pattern.
- Check digit
- An extra digit, calculated from the others, appended to a number to check it has been entered without error.
- Double entry / visual check
- Entering data twice and comparing the copies / the user checking data on screen before confirming it.
Homework 1 min
Task (≤ 15 min): A phone app splits a restaurant bill between diners. It works for 2 to 12 diners and bills from $10 to $500. (a) State the validation checks needed for each input, with reasons. [4] (b) Write pseudocode for the check on the number of diners. [3]
Model answer
- Diners: type check — whole number, as people cannot be split (1); range check 2–12, the app's limits (1).
- Bill: type check — a number / real (1); range check $10–$500 (1). A presence check on both is also acceptable.
REPEAT
OUTPUT "Number of diners (2-12): "
INPUT Diners
IF Diners < 2 OR Diners > 12
THEN
OUTPUT "Must be 2 to 12"
ENDIF
UNTIL Diners >= 2 AND Diners <= 12Marks: loop (1); correct rejection test and message (1); correct UNTIL condition (1).