← IGCSE Computer Science Paper 2

Format check

A check that input follows a set pattern of characters, such as a date written DD/MM/YYYY. The right pattern does not prove the data is correct, e.g. 99/99/2025 fits the pattern.

Understanding Format check in IGCSE Computer Science Paper 2

What it does: Combining LENGTH and SUBSTRING with AND checks that the whole DD/MM/YYYY pattern is followed, because every test must be true. A format check tests the pattern of characters. Checking that a number lies between 0 and 100 is a range check. SUBSTRING(Date, 3, 1) takes 1 character starting at position 3. LENGTH returns a number, so it cannot equal "/". DD/MM/YYYY has 2 + 1 + 2 + 1 + 4 = 10 characters, including the two slashes.

Common mistakes: In DD/MM/YYYY the first slash is the 3rd character, so the check must be SUBSTRING(D,3,1). Position 2 is part of the day. When the length is not 10 the format is wrong, so V must be set to FALSE. Setting it to TRUE means a wrongly formatted date is accepted.

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 47–57) 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
Which input is checked by a format check?
A date must be written as DD/MM/YYYYA mark must be between 0 and 100
Matches
IF SUBSTRING(Date, 3, 1) = "/" THEN OUTPUT "Date is correct" ENDIF
↓
A format check only shows that the pattern is right, not that the date is correct. 99/99/2025 would pass, so the output should say the format is valid.
Applying
Meanings
Term
format check
Meaning
A check that input follows a set pattern of characters, such as a date written DD/MM/YYYY. The right pattern does not prove the data is correct, e.g. 99/99/2025 fits the pattern.
Practice
REPEAT
Testing
Gaps
IF LENGTH(Date) <> THEN
Check Answer
Spots
2INPUT D
3IF SUBSTRING(D,2,1) = "/" THEN

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

The 'Pufferfish' badge — Error Handler, 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. Which input is checked by a format check?
A. A date must be written as DD/MM/YYYY ✓
B. A mark must be between 0 and 100
A format check tests the pattern of characters. Checking that a number lies between 0 and 100 is a range check.
2. Which pseudocode condition tests that the 3rd character of Date is a slash?
A. SUBSTRING(Date, 3, 1) = "/" ✓
B. LENGTH(Date) = "/"
SUBSTRING(Date, 3, 1) takes 1 character starting at position 3. LENGTH returns a number, so it cannot equal "/".
3. A date must be DD/MM/YYYY. Which check on LENGTH(Date) is correct for the full pattern?
A. LENGTH(Date) = 10 ✓
B. LENGTH(Date) = 8
DD/MM/YYYY has 2 + 1 + 2 + 1 + 4 = 10 characters, including the two slashes.
4. The user enters 99/99/2025 and the format check for DD/MM/YYYY passes. What does this show?
A. The date is correct, so it must be a real date
B. The pattern is right, but the data is not a real date ✓
A format check only tests the pattern. 99/99/2025 fits the pattern but is not a valid date, so the data is still wrong.
5. Which two checks combine to test the DD/MM/YYYY format more fully?
A. LENGTH(Date) = 10 OR SUBSTRING(Date, 3, 1) = "/"
B. LENGTH(Date) = 10 AND SUBSTRING(Date, 3, 1) = "/" ✓
AND means both conditions must be true. With OR, a wrong input could pass if only one condition was true.

Match the Pairs

SUBSTRING(Date, 3, 1) = "/" → Checks that the 3rd character of a date is a slash, which is part of a DD/MM/YYYY format check
LENGTH(Date) = 10 → Checks that a DD/MM/YYYY date has exactly 10 characters, which is one part of a format check
A format check can test that a date has the right length and a slash in the 3rd and 6th positions → LENGTH(Date) = 10 AND SUBSTRING(Date, 3, 1) = "/" AND SUBSTRING(Date, 6, 1) = "/"
An email format check can test that the input contains an @ symbol in the expected place → SUBSTRING(Email, 5, 1) = "@"
IF SUBSTRING(Date, 3, 1) = "/" THEN OUTPUT "Date is correct" ENDIF → A format check only shows that the pattern is right, not that the date is correct. 99/99/2025 would pass, so the output should say the format is valid.
IF SUBSTRING(Date, 3) = "/" THEN → SUBSTRING needs three arguments: the string, the start position and the number of characters. The length 1 is missing, so it should be SUBSTRING(Date, 3, 1).

Key Term

format check
A check that input follows a set pattern of characters, such as a date written DD/MM/YYYY. The right pattern does not prove the data is correct, e.g. 99/99/2025 fits the pattern.

Fill in the Blanks

1. IF LENGTH(Date) <> 10 THEN OUTPUT "Wrong format" ENDIF
Hint: Type the number of characters in a date written DD/MM/YYYY, including the slashes.
2. IF SUBSTRING(Date, 3, 1) <> "/" THEN OUTPUT "Wrong format" ENDIF
Hint: Type the position of the first slash in DD/MM/YYYY.
3. IF SUBSTRING(Date, 6, 1) = "/" THEN OUTPUT "Second slash found" ENDIF
Hint: Type the function that extracts part of a string so one character can be checked.
4. IF LENGTH(Date) = 10 AND SUBSTRING(Date, 6, 1) = "/" THEN
Hint: Type the logical operator that needs both the length check and the slash check to be true.
5. Date ← "99/99/2025" IF LENGTH(Date) = 10 THEN OUTPUT "Format check passed"
Hint: Type the command that displays a message. This date fits the pattern even though the data is not correct.

Spot the Error

Question 1
A OUTPUT "Enter DD/MM/YYYY"
B INPUT D
C IF SUBSTRING(D,2,1) = "/" THEN
D OUTPUT "Slash found"
E ENDIF
Line C — In DD/MM/YYYY the first slash is the 3rd character, so the check must be SUBSTRING(D,3,1). Position 2 is part of the day.
Question 2
A INPUT D
B V ← TRUE
C IF LENGTH(D) <> 10 THEN
D V ← TRUE
E ENDIF
Line D — When the length is not 10 the format is wrong, so V must be set to FALSE. Setting it to TRUE means a wrongly formatted date is accepted.
Question 3
A INPUT D
B V ← TRUE
C IF SUBSTRING(D,6,1) = "/" THEN
D V ← FALSE
E ENDIF
Line C — The condition should be <> so V becomes FALSE when the 6th character is NOT a slash. With = a correct date would be rejected.
Question 4
A INPUT T
B C ← SUBSTRING(T,3,1)
C L ← LENGTH(T)
D IF L = 5 OR C = ":" THEN
E OUTPUT "Format OK"
F ENDIF
Line D — A HH:MM time must have BOTH length 5 AND a colon in position 3. OR lets data pass when only one part of the pattern is right, so it should be AND.
Question 5
A DECLARE D : INTEGER
B INPUT D
C IF LENGTH(D) = 10 THEN
D OUTPUT "Right length"
E ENDIF
Line A — A date such as 12/05/2025 contains slashes, so it must be stored as a STRING. LENGTH and SUBSTRING also work on strings, not integers.

Student with a class code? Join your class →