Format check

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Format check

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

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
2. Which pseudocode condition tests that the 3rd character of Date is a slash?
A SUBSTRING(Date, 3, 1) = "/"
B LENGTH(Date) = "/"
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
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
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) = "/"

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1SUBSTRING(Date, 3, 1) = "/" ALENGTH(Date) = 10 AND SUBSTRING(Date, 3, 1) = "/" AND SUBSTRING(Date, 6, 1) = "/"
2LENGTH(Date) = 10 BSUBSTRING(Email, 5, 1) = "@"
3A format check can test that a date has the right length and a slash in the 3rd and 6th positions CSUBSTRING 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).
4An email format check can test that the input contains an @ symbol in the expected place DChecks that the 3rd character of a date is a slash, which is part of a DD/MM/YYYY format check
5IF SUBSTRING(Date, 3, 1) = "/" THEN OUTPUT "Date is correct" ENDIF EChecks that a DD/MM/YYYY date has exactly 10 characters, which is one part of a format check
6IF SUBSTRING(Date, 3) = "/" THEN FA 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.

Definitions

format check

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF LENGTH(Date) <> __ THEN OUTPUT "Wrong format" ENDIF
2.
IF SUBSTRING(Date, _, 1) <> "/" THEN OUTPUT "Wrong format" ENDIF
3.
IF _________(Date, 6, 1) = "/" THEN OUTPUT "Second slash found" ENDIF
4.
IF LENGTH(Date) = 10 ___ SUBSTRING(Date, 6, 1) = "/" THEN
5.
Date ← "99/99/2025" IF LENGTH(Date) = 10 THEN ______ "Format check passed"

Spot the Error

Shade in the letter of the line that contains an 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
Question 2
A INPUT D
B V ← TRUE
C IF LENGTH(D) <> 10 THEN
D V ← TRUE
E ENDIF
Question 3
A INPUT D
B V ← TRUE
C IF SUBSTRING(D,6,1) = "/" THEN
D V ← FALSE
E ENDIF
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
Question 5
A DECLARE D : INTEGER
B INPUT D
C IF LENGTH(D) = 10 THEN
D OUTPUT "Right length"
E ENDIF

Answer Key

Format check
Section A: Quick Questions
Q1
A — A date must be written as DD/MM/YYYY
Q2
A — SUBSTRING(Date, 3, 1) = "/"
Q3
A — LENGTH(Date) = 10
Q4
B — The pattern is right, but the data is not a real date
Q5
B — LENGTH(Date) = 10 AND SUBSTRING(Date, 3, 1) = "/"
Section B: Match the Pairs
Q1
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
Q2
LENGTH(Date) = 10 → Checks that a DD/MM/YYYY date has exactly 10 characters, which is one part of a format check
Q3
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) = "/"
Q4
An email format check can test that the input contains an @ symbol in the expected place → SUBSTRING(Email, 5, 1) = "@"
Q5
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.
Q6
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).
Section C: Definitions
Q1
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.
Section D: Fill in the Blanks
Q1
IF LENGTH(Date) <> 10 THEN OUTPUT "Wrong format" ENDIF
Q2
IF SUBSTRING(Date, 3, 1) <> "/" THEN OUTPUT "Wrong format" ENDIF
Q3
IF SUBSTRING(Date, 6, 1) = "/" THEN OUTPUT "Second slash found" ENDIF
Q4
IF LENGTH(Date) = 10 AND SUBSTRING(Date, 6, 1) = "/" THEN
Q5
Date ← "99/99/2025" IF LENGTH(Date) = 10 THEN OUTPUT "Format check passed"
Section E: Spot the Error
Q1
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.
Q2
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.
Q3
C — The condition should be <> so V becomes FALSE when the 6th character is NOT a slash. With = a correct date would be rejected.
Q4
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.
Q5
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.