← IGCSE Computer Science Paper 2

Choosing a validation check for a field

A test matched to the field: range for age, length and type for PIN, presence for name, format for dates or postcodes, check digit for ISBN. Always justify the choice.

Understanding Choosing a validation check for a field in IGCSE Computer Science Paper 2

What it does: Length check tests the number of characters and type check tests they are digits, which together cover the PIN rules. A check digit is calculated from the other digits and recalculated to detect mistyped or swapped digits in ISBNs and barcodes. A format check tests that data follows a set pattern. Dates and postcodes have a fixed layout, so a format check suits them. A good justification links the check to what the field must contain. Here the data is a number with a lower and upper limit, so a range check is correct.

Common mistakes: A range check on age rejects a value that is too low OR too high. No number is both below 0 and above 120, so AND never rejects anything. It should be OR. A length check must count the characters with LENGTH(PIN). Comparing PIN itself with 4 tests the value, not how many characters it has. It should be WHILE LENGTH(PIN) <> 4 DO.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 60–70) and word search (Modules 47–70).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A form asks for a student's age, which must be between 11 and 18. Which validation check is the best choice?
Range checkPresence check
Matches
Postcode field: use a range check (1 to 9999)
↓
A postcode is a pattern of letters and digits, so it needs a format check, not a range check.
Applying
Meanings
Term
validation check
Meaning
A test matched to the field: range for age, length and type for PIN, presence for name, format for dates or postcodes, check digit for ISBN. Always justify the choice.
Practice
// Age: RANGE check, must be 0 to 120
Testing
Gaps
IF Age >= 0 Age <= 120 THEN
Check Answer
Spots
2INPUT Age
3WHILE Age < 0 AND Age > 120 DO

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Sperm Whale' badge — Deep Sea Champion, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A form asks for a student's age, which must be between 11 and 18. Which validation check is the best choice?
A. Presence check
B. Range check ✓
A range check tests that a number lies between a lower and upper limit, so it suits an age that must be 11 to 18. A presence check only tests that something was entered.
2. A 4-digit PIN is being entered. Which pair of checks suits this field?
A. Length check and type check ✓
B. Range check and format check
A PIN must be exactly 4 characters long (length check) and contain only digits (type check). Justify the choice by saying what the field must contain.
3. A user must not leave the Name field blank. Which check should you choose?
A. Check digit
B. Presence check ✓
A presence check makes sure data has been entered. A check digit is used for numbers such as barcodes and ISBNs, not for names.
4. A postcode must follow a set pattern of letters and numbers, such as 'AB12 3CD'. Which check is best?
A. Format check ✓
B. Range check
A format check tests that data follows a set pattern. Dates and postcodes have a fixed layout, so a format check suits them.
5. A shop scans ISBN numbers on books. Which check can detect a mistyped digit?
A. Check digit ✓
B. Presence check
A check digit is calculated from the other digits of the ISBN or barcode. If a digit is mistyped, the recalculated value does not match and the error is found.

Match the Pairs

Age: range check (0 to 120) → Age is a number that must sit between a lowest and highest sensible value, so a range check is the best choice.
Name: presence check → A name must not be left empty, so a presence check is chosen to make sure something has been entered.
A PIN must be exactly 4 digits, so a length check and a type check are both needed → LENGTH(PIN) = 4 AND PIN is all digits
An ISBN or barcode can be checked for typing errors using its last digit, so a check digit is chosen → Recalculate the check digit and compare it
Postcode field: use a range check (1 to 9999) → A postcode is a pattern of letters and digits, so it needs a format check, not a range check.
Age field: use a presence check to make sure age is sensible → A presence check only tests that something was entered, so 500 would still pass. Use a range check for age.

Key Term

validation check
A test matched to the field: range for age, length and type for PIN, presence for name, format for dates or postcodes, check digit for ISBN. Always justify the choice.

Fill in the Blanks

1. // Age must be between 0 and 120 IF Age >= 0 AND Age <= 120 THEN OUTPUT "Age accepted"
Hint: Type the logical operator that needs both limits to be met in a range check.
2. // PIN must have exactly 4 digits IF LENGTH(PIN) <> 4 THEN OUTPUT "PIN must be 4 characters"
Hint: Type the function that counts how many characters are in the PIN (a length check).
3. INPUT Name IF LENGTH(Name) = 0 THEN OUTPUT "Name is required"
Hint: Type the number of characters in an empty name (a presence check).
4. // Date of birth needs a format check
Hint: Type the name of the check that tests the pattern of a date, such as day, month and year layout.
5. // ISBN: validate using a check digit
Hint: Type the check for a barcode or ISBN, where a calculated final digit is compared with the digit entered.

Spot the Error

Question 1
A // Age field: range check
B INPUT Age
C WHILE Age < 0 AND Age > 120 DO
D OUTPUT "Enter 0 to 120"
E INPUT Age
F ENDWHILE
Line C — A range check on age rejects a value that is too low OR too high. No number is both below 0 and above 120, so AND never rejects anything. It should be OR.
Question 2
A INPUT PIN
B WHILE PIN <> 4 DO
C OUTPUT "PIN must be 4 chars"
D INPUT PIN
E ENDWHILE
Line B — A length check must count the characters with LENGTH(PIN). Comparing PIN itself with 4 tests the value, not how many characters it has. It should be WHILE LENGTH(PIN) <> 4 DO.
Question 3
A INPUT Name
B WHILE Name <> "" DO
C OUTPUT "Name is required"
D INPUT Name
E ENDWHILE
Line B — A presence check must repeat the question when the field is empty. Name <> "" repeats when something has been entered, which is backwards. It should be WHILE Name = "" DO.
Question 4
A CASE OF Field
B "Age": Check ← "Range"
C "Name": Check ← "Presence"
D "Date": Check ← "Range"
E ENDCASE
Line D — A date has a fixed pattern such as DD/MM/YYYY, so a format check is the best fit. A range check suits numbers like age. The line should assign "Format".
Question 5
A Field ← "ISBN"
B Check ← "Presence check"
C Reason ← "Detects typos"
D OUTPUT Check, Reason
Line B — An ISBN needs a check digit, which is calculated from the other digits and detects mistyped numbers. A presence check only tests that something was entered. It should be "Check digit".

Student with a class code? Join your class →