Study Guide
Validation and Verification
How a program can notice data that is impossible or mistyped: validation checks (range, length, type, presence, format and check digit), verification checks (visual and double entry), and how to write validation in pseudocode.
Lesson 5.12 Algorithms and Programming
For: Cambridge IGCSE Computer Science learners, or Key Stage 3 learners who can write loops and selection (about ages 13 to 14)
Stage: Think
Three mistakes on one form
Riverside School (a fictional school) is booking a trip, and a parent fills in an online form for Mia Khan, who is 14. Three different people make a mistake in the box labelled “Pupil’s age”. Ali types 140. Ben types fourteen, in words. Cara types 15.
Think it through
The program does not know Mia’s real age. Which of the three mistakes could it still notice, and which could it not? Explain why.
- Hint 1: For each entry, ask: could this be a real pupil’s age?
- Hint 2: Ask also whether the program could use the entry in a calculation.
Show a model answer
It could notice 140 and “fourteen”. 140 is not a possible age for a pupil, and “fourteen” is words rather than a number the program can use, so both break a rule about what is allowed. It could not notice 15: that is a perfectly possible age, so nothing about it looks wrong. Only someone who knows Mia’s real age, or a second copy of it to compare with, could spot it.
Stage: Discover
Rules about what is allowed
The trip is for pupils aged 11 to 18. The booking site also asks the parent to choose a password, which must be from 8 to 12 characters long.
Think it through
Write each of these two rules as a comparison a program could test, using AND. Use the variable names Age and Password.
- Hint 1: An age is allowed if it is at least 11 and at most 18.
- Hint 2: LENGTH(Password) gives the number of characters in the password.
Show a model answer
Age >= 11 AND Age <= 18, and LENGTH(Password) >= 8 AND LENGTH(Password) <= 12.
A check that the program makes on data as it is typed in, to see whether the data is sensible and allowed, is validation. A program that validates its input refuses data that breaks a rule and asks again. There are several kinds of rule. Two of them are the ones you have just written:
- A range check tests that a value lies between the lowest and the highest allowed. The age rule is a range check, and 11 and 18 themselves are allowed.
- A length check tests that the data has an allowed number of characters. It can ask for an exact length (a code that is always 6 characters) or for a minimum and maximum, as the password rule does.
INPUT Age
IF Age >= 11 AND Age <= 18
THEN
OUTPUT "Age accepted"
ELSE
OUTPUT "Age must be from 11 to 18"
ENDIFCheck your understanding
Show the answer
Answer: C. 18
A range check has two limits, and each limit is itself allowed when the comparison is >= or <=.
Check your understanding
Show the answer
Answer: A. Yes: it has 10 characters, which is from 8 to 12.
A length check counts characters of every kind.
Stage: Discover
The right kind of data, and some data at all
The next box on the form asks “How many tickets?”.
Think it through
List three different things a person might type, or fail to type, in the “How many tickets?” box that the program cannot use. Why can it not use each?
- Hint 1: Think about letters, about leaving the box alone, and about numbers that are not whole.
Show a model answer
For example: the word “two” (the program needs a number); nothing at all (the box was skipped, so there is no value); 2.5 (tickets are whole, so a number with a fractional part makes no sense); a negative number such as -3. Each one breaks a different rule.
Two more kinds of check deal with the first two of those mistakes:
- A type check tests that the data is of the right data type. For tickets that means a whole number (an integer), so “two” and 2.5 are both refused.
- A presence check tests that something has been entered at all. An empty box is refused, which matters for any item the program cannot work without, such as a name.
In pseudocode the presence check compares the input with an empty string: UNTIL Name <> "". A type check is usually left to the language: Python, for example, can test text with .isdigit(), which you will see in the Python box later. In an exam question you can describe the type check in words, such as “check that Tickets is an integer”.
Passing every validation check does not make data correct. Validation can only show that the data is possible: it follows the rules. Cara’s 15 passes the range check for Mia’s age, because 15 is between 11 and 18, even though Mia is 14. A program that validates is protected from impossible data, but not from a wrong value that looks reasonable.
Check your understanding
Show the answer
Answer: D. A presence check, because nothing was entered.
A presence check asks only whether something was entered.
Check your understanding
Show the answer
Answer: B. That 15 follows the rules for an age here, but may not be Mia’s real age.
Validation answers “is this allowed?”, never “is this true?”.
Stage: Discover
Data that must follow a pattern
The form asks for the date of the trip in the form 05/11/2026: two digits, a slash, two digits, a slash and four digits.
Think it through
Describe in words a rule a program could test to refuse 5/11/26 and 05-11-2026 but accept 05/11/2026. Which characters would it look at?
- Hint 1: Count the characters in a correct date.
- Hint 2: Which positions hold the slashes?
Show a model answer
A correct date has 10 characters, and the characters in positions 3 and 6 are slashes. 5/11/26 has only 7 characters, and 05-11-2026 has hyphens in positions 3 and 6, so both break the rule.
A format check tests that data follows a set pattern. The pattern for this date can be tested with the string routines from Lesson 8: the length must be 10, and SUBSTRING(Date, 3, 1) and SUBSTRING(Date, 6, 1) must both be "/".
IF LENGTH(Date) = 10 AND SUBSTRING(Date, 3, 1) = "/" AND SUBSTRING(Date, 6, 1) = "/"
THEN
OUTPUT "Date accepted"
ELSE
OUTPUT "Please type the date as 05/11/2026"
ENDIFWork out what the check does with four typed dates:
| Typed | LENGTH | Character 3 | Character 6 | Accepted? |
|---|---|---|---|---|
| 05/11/2026 | 10 | / | / | Yes |
| 5/11/2026 | ||||
| 05-11-2026 | 10 | |||
| 31/02/2026 | 10 | / | / |
Show the completed table
| Typed | LENGTH | Character 3 | Character 6 | Accepted? |
|---|---|---|---|---|
| 05/11/2026 | 10 | / | / | Yes |
| 5/11/2026 | 9 | 1 | 2 | No |
| 05-11-2026 | 10 | - | - | No |
| 31/02/2026 | 10 | / | / | Yes |
31/02/2026 is accepted even though there is no 31st of February.
Check your understanding
Show the answer
Answer: A. It checks the pattern of characters, not whether the date is real.
Like every validation check, a format check can show that data has the right shape and no more.
Stage: Explain
Spotting a mistyped number: the check digit
Riverside School’s library gives each member a card number of six digits. It is a fictional scheme, but real ones work the same way.
Think it through
A librarian types the card number 842134 instead of 482134 by swapping the first two digits. The typed number has six digits, all of them digits, and it is in the allowed range. How could the computer still notice that something is wrong?
- Hint 1: What if one of the digits had been worked out from the others?
- Hint 2: Could the computer repeat that working out when the number is typed?
Show a model answer
If the last digit is worked out from the other five by a fixed calculation, the computer can repeat the calculation on whatever has been typed and compare its answer with the last digit. A mistyped number will usually give a different answer, so the mismatch shows that something is wrong.
A check digit is a digit added to a number, worked out from its other digits, so that a mistake can be noticed when the number is typed or scanned. The library’s rule (invented for this lesson, but the same idea as in ISBNs and bar codes) is:
- Multiply the first five digits by the weights 1, 3, 1, 3, 1, working from the left.
- Add the five products.
- Find the remainder when the total is divided by 10.
- The check digit is 10 minus that remainder. If the remainder is 0, the check digit is 0.
- Multiply each digit by its weight. 4 × 1 = 4, 8 × 3 = 24, 2 × 1 = 2, 1 × 3 = 3 and 3 × 1 = 3. (The weights alternate so that swapping two neighbouring digits usually changes the total.)
- Add the products. 4 + 24 + 2 + 3 + 3 = 36.
- Find the remainder when divided by 10. 36 leaves a remainder of 6.
- Subtract the remainder from 10. 10 − 6 = 4, so the check digit is 4 and the full card number is 482134.
Now work out one yourself, and then check the number the librarian typed.
| Digit | Weight | Digit × weight |
|---|---|---|
| 3 | 1 | 3 |
| 1 | 3 | |
| 5 | 1 | |
| 0 | 3 | |
| 2 | 1 | |
| Total | ||
| Remainder when divided by 10 | ||
| Check digit (10 − remainder) |
Show the completed table
| Digit | Weight | Digit × weight |
|---|---|---|
| 3 | 1 | 3 |
| 1 | 3 | 3 |
| 5 | 1 | 5 |
| 0 | 3 | 0 |
| 2 | 1 | 2 |
| Total | 13 | |
| Remainder when divided by 10 | 3 | |
| Check digit (10 − remainder) | 7 |
| Step | Working | Result |
|---|---|---|
| Digits used | First five digits: 8, 4, 2, 1, 3 | |
| Products | 8 × 1, 4 × 3, 2 × 1, 1 × 3, 3 × 1 | |
| Total | Add the products | |
| Check digit that the rule gives | 10 − (the remainder of 28 ÷ 10) | |
| Typed check digit | The sixth digit | 4 |
| Verdict | Do the two check digits match? |
Show the completed table
| Step | Working | Result |
|---|---|---|
| Digits used | First five digits: 8, 4, 2, 1, 3 | |
| Products | 8 × 1, 4 × 3, 2 × 1, 1 × 3, 3 × 1 | 8, 12, 2, 3, 3 |
| Total | Add the products | 28 |
| Check digit that the rule gives | 10 − (the remainder of 28 ÷ 10) | 2 |
| Typed check digit | The sixth digit | 4 |
| Verdict | Do the two check digits match? | No |
Check your understanding
Show the answer
Answer: C. It rejects it: the check digit worked out is 2, but the typed one is 4.
A check digit catches many typing mistakes, but not all: it shows that a number is probably typed correctly, not that it belongs to the right member.
The Networks lesson Error Detection teaches the check digits used in ISBN-13 numbers and bar codes, including how they are checked. This lesson uses a smaller invented rule so that you can see how a check digit works as one kind of validation.
Stage: Predict
Is it what was meant?
Ali types his email address into the booking form. It passes every validation check, but he has typed ali.kahn@school.example instead of ali.khan@school.example. Every character is allowed, so no validation rule can refuse it.
Think it through
Suggest two different ways of catching the swapped letters, one that a person does and one that the program does.
- Hint 1: One way uses the screen. The other asks Ali to do something twice.
Show a model answer
A person could read the address back on the screen and compare it with the original they were copying from. The program could ask for the address twice and refuse it unless both entries are identical.
Verification is a check that data has been entered as it was meant to be, rather than a check that it is allowed. Two methods are common:
- A visual check is made by the person who typed. The program shows the data back, for example “You typed ali.kahn@school.example: is this correct?”, and the person compares it with the original.
- A double entry check has the data typed twice. The program compares the two entries and accepts them only if they are identical.
REPEAT
OUTPUT "Enter your email address:"
INPUT Email1
OUTPUT "Enter it again:"
INPUT Email2
IF Email1 <> Email2
THEN
OUTPUT "The two entries do not match. Please try again."
ENDIF
UNTIL Email1 = Email2Do not confuse: Validation and verification
- What does it ask?Validation
- Is this data sensible and allowed by the rules?Age 140 is refused by a range check.
- What does it ask?Verification
- Is this the data that was meant, the same as the original or the second entry?ali.kahn is caught because it differs from the second entry.
Neither can prove data is true. A program normally uses both, because each catches mistakes the other cannot.
Check your understanding
Show the answer
Answer: D. That a repeated mistake matches itself, so the check does not notice it.
No single check catches every mistake.
Stage: Explain
Writing validation that asks again
Think it through
A program must keep asking for the age until a valid one is typed. Should the loop test the age before the first input or after it? Which of the three loops from Lesson 5 would you choose, and why?
- Hint 1: Can the program test an age before the user has typed one?
Show a model answer
It must ask at least once before there is anything to test, so the test comes after the input: a post-condition loop, REPEAT … UNTIL. A pre-condition WHILE loop would need an extra INPUT before the loop to give it something to test.
- Choose the loop. The age must be asked for at least once, so
REPEAT … UNTILis used: it tests after the input. - Ask and read.
OUTPUTthe prompt, thenINPUT Age, inside the loop, so a refused age is asked for again. - Give a helpful message. If the age breaks the rule, tell the person what is wrong and what is allowed. “Invalid” alone leaves them guessing.
- Write the loop condition as the opposite of the error. The loop must stop when the age is valid, so the
UNTILcondition is the allowed range:Age >= 11 AND Age <= 18. TheIFinside uses the refused range:Age < 11 OR Age > 18.
REPEAT
OUTPUT "Enter your age (11 to 18):"
INPUT Age
IF Age < 11 OR Age > 18
THEN
OUTPUT "Age must be from 11 to 18. Please try again."
ENDIF
UNTIL Age >= 11 AND Age <= 18Trace it for the three ages Ben types in turn: 9, then 25, then 14.
| Attempt | Age typed | Message shown? | Does the loop end? |
|---|---|---|---|
| 1 | 9 | ||
| 2 | 25 | ||
| 3 | 14 |
Show the completed table
| Attempt | Age typed | Message shown? | Does the loop end? |
|---|---|---|---|
| 1 | 9 | Yes | No |
| 2 | 25 | Yes | No |
| 3 | 14 | No | Yes |
Check your understanding
Show the answer
Answer: B. It accepts every number, because every number is at least 11 or at most 18.
For a range, the allowed condition joins its two parts with AND; the refused condition joins them with OR.
Stage: Apply
Write validation yourself
Think it through
Write pseudocode that asks for a password and keeps asking until its length is from 8 to 12 characters. Show a helpful message each time a password is refused.
Work this out on paper or the board first. Nothing here is marked: compare yours with the model answer.
- Hint 1: Use REPEAT … UNTIL, as in the age example.
- Hint 2: Use LENGTH(Password) for the number of characters.
Show a model answer
REPEAT
OUTPUT "Choose a password (8 to 12 characters):"
INPUT Password
IF LENGTH(Password) < 8 OR LENGTH(Password) > 12
THEN
OUTPUT "The password must have from 8 to 12 characters. Please try again."
ENDIF
UNTIL LENGTH(Password) >= 8 AND LENGTH(Password) <= 12The IF and the UNTIL use opposite conditions. A presence check on its own would be UNTIL Password <> "", but this length check already refuses an empty password, because its length is 0.
Go deeper The same ideas in Python
def valid_age(text):
return text.isdigit() and 11 <= int(text) <= 18
age = input("Enter your age (11 to 18): ")
while not valid_age(age):
print("Age must be a whole number from 11 to 18. Please try again.")
age = input("Enter your age (11 to 18): ")
age = int(age)
print("Age accepted:", age)inputalways gives text, so the type check comes first:text.isdigit()is true only when the text is made of digits. Becauseandstops as soon as it knows the answer,int(text)is only tried on text that is made of digits.- Python’s loop that asks again is a
whileloop that tests first, so the first input is read before the loop and again at the end of each pass. - The check digit calculation is a loop over the digits, with
int(digit)to turn each character into a number:
def check_digit(first_five):
total = 0
for position, digit in enumerate(first_five):
weight = 1 if position % 2 == 0 else 3
total = total + int(digit) * weight
return (10 - total % 10) % 10
print(check_digit("48213"))
print(check_digit("31502"))This prints 4 and then 7. The final % 10 makes the check digit 0, rather than 10, when the remainder is 0.
Stage: Apply
Choosing the check
Apply it
Show the answer
Answer: C. A range check, because the value must lie between 7 and 11.
Two limits mean a range check.
Apply it
Show the answer
Answer: A. A length check, because it has four characters and six are needed.
The wrong number of characters is exactly what a length check refuses.
Apply it
Show the answer
Answer: B. A presence check, a type check and a range check.
Several checks are often combined on one input.
Stage: Consolidate
Show what you know
Think it through
Explain the difference between validation and verification to someone who missed the lesson. Use the age on Mia’s form as your example, and say which of Ali’s, Ben’s and Cara’s mistakes each could catch.
Show a model answer
A good answer says that validation checks that data follows rules about what is allowed (a range check refuses Ali’s 140 and a type check refuses Ben’s “fourteen”), while verification checks that data is what was meant, by comparing it with the original or with a second entry. Cara’s 15 is allowed, so validation cannot refuse it. Only verification, such as a visual check against Mia’s details, could catch it.
Apply it
Show the answer
Answer: D. A double entry check, a method of verification.
Typing data twice to compare is verification.
- Validation checks that data is sensible and allowed: range, length, type, presence, format and check digit. It cannot show that data is true.
- Verification checks that data is what was meant: a visual check against the original, or a double entry check that compares two entries. A repeated mistake can still pass.
- Validation in pseudocode is a
REPEAT … UNTILloop that asks again, with a helpful message. TheIFuses the refused values and theUNTILuses the allowed ones. - Use several checks together, because each catches mistakes that the others cannot.
Sources and scope
- What this lesson is. The twelfth lesson of the Algorithms and Programming module, written for this site. It covers point 7.5 of Cambridge IGCSE Computer Science 0478 (2026 to 2028, version 6) on validation and verification, with validation written in pseudocode. Its curriculum links are provisional and imply no review or endorsement by any examination board.
- Original material. Riverside School, Mia, Ali, Ben, Cara, Sam, the trip form and the library card scheme are fictional, written for this lesson. The check digit rule is invented to show the idea; it is not the rule of any real scheme. The pseudocode follows the layout in the syllabus’s pseudocode guide, and each program’s output was worked out by hand.
- Simplified on purpose. Only the checks listed in the syllabus’s notes and guidance are taught. Existence checks, limit checks and checks during data transfer (A Level) are left out. Type checking is shown in Python and in words, because the pseudocode guide has no routine for it.
- Left to later lessons. Choosing test data for these checks (Lesson 13), finding errors in algorithms (Lesson 14) and writing a whole program for a scenario (Lesson 16). The Networks lesson Error Detection teaches the standard check digits of ISBNs and bar codes.
A sequence of precise steps that solves a problem or completes a task.
A digit added to a number, worked out from its other digits, so that a mistake in typing or scanning can be noticed.
The kind of value a variable holds, such as a whole number or text. It decides what the program can do with the value.
A verification check in which data is typed twice and the program accepts it only if the two entries are identical.
A validation check that data follows a set pattern, such as two digits, a slash, two digits, a slash and four digits for a date.
A validation check that data has an allowed number of characters, such as exactly 6, or from 8 to 12.
A loop that tests its condition after each repeat, so its instructions always run at least once. In pseudocode it is a REPEAT … UNTIL loop.
A loop that tests its condition before each repeat, so its instructions may run zero times. In pseudocode it is a WHILE … ENDWHILE loop.
A validation check that something has been entered, so that a required item is not left empty.
The text (or other input) given to an AI system to tell it what to do.
A precise but language-independent way of writing an algorithm, with set keywords such as IF, WHILE and OUTPUT, that is not tied to any one programming language.
A high-level programming language written as text, popular for learning and for real work, in which indentation shows which lines belong together.
A validation check that a value lies between the lowest and the highest value allowed.
Values chosen to test a program, with the correct result for each worked out before the test is run.
A validation check that data is of the right data type, such as a whole number rather than letters.
An automatic check, made by a program or a database, that data is sensible and allowed before it is accepted, such as a number being inside a set range. It cannot show that the data is correct.
A check that data has been entered as it was meant to be, for example by comparing it with the original or with a second entry.
A verification check in which the person who typed the data reads it back on the screen and compares it with the original.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.