Community resourceWorksheet
1CP2-CT-4.4 Validating user input
Part 4 of 7 · 1CP2-CT-4 · Structures, validation and search
The validation worksheet, covering the four standard checks and the loop that applies them until the input is acceptable.
Students will:
- match a rule to the validation check that tests it
- explain why a value is validated before it is used in a calculation
- apply a format or pattern check
- write the Boolean condition that is true when input is invalid
- distinguish validation from verification and authentication
Inside: 7 explanation cells, 3 multiple-choice questions, 1 Python task, 1 fill-in-the-blanks cell and 2 written answers. 16 marks, about 45 minutes.
Series: 1CP2-CT-4 · Structures, validation and search, part 4 of 7.
Shared by Coding PathwayVerified teacher
- 14 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Validating user input
Validation checks whether input satisfies stated rules before a program accepts and uses it. It reduces unsuitable data; it does not prove that accepted data is true or belongs to the person entering it.
1. Four required checks
| Check | Question it answers | Example rule |
|---|---|---|
| Presence | Was anything entered? | name != "" |
| Length | Is the number of characters acceptable? | len(code) == 6 |
| Range | Is a value between limits? | rating >= 1 and rating <= 5 |
| Pattern | Do characters follow a simple required form? | first two alphabetic, final four digits |
Pearson expects simple pattern checks using string manipulation functions. Regular expressions are unnecessary and outside this route.
- length
- pattern
- presence
- range
- type
A username must contain at least six characters. Which validation check directly tests this rule?
- APresence check
- BLength check
- CRange check
- DAuthentication check
Explain why a cinema booking program should validate a requested ticket quantity before calculating a total.
Give the rule and the consequence of accepting unsuitable data.
Students type their answer here.
2. Build a simple pattern check
For a code that must contain two letters followed by four digits:
valid_pattern = len(code) == 6 and code[0:2].isalpha() and code[2:6].isdigit()
The length check happens alongside the slice checks. .isalpha() and .isdigit() examine the character groups; they do not authenticate who supplied the code.
Which input passes the six-character pattern of two letters followed by four digits?
- A`A12345`
- B`AB1234`
- C`ABC123`
- D`1212AB`
3. Reject repeatedly, not just once
if checks once; a while can keep asking.
An if can report one invalid entry but then continues. A while loop can keep asking until the rule is satisfied. The loop condition usually describes what is invalid because the program repeats while the problem remains.
A rating is valid from 1 to 5 inclusive. Write the Boolean condition that is true when the rating is invalid, and explain why it uses or.
Consider values below the minimum or above the maximum.
Students type their answer here.
4. Construct repeated range validation
Ask for an integer quantity. Keep asking while it is below 1 or above 8. When a valid quantity is entered, print Accepted: followed by the number. Your solution will be tested with a valid first entry and with invalid entries before a valid one.
# Ask for quantity, repeat until it is 1 to 8, then print acceptance.
5. Validation is not verification or authentication
Validation asks whether data follows rules. Verification checks whether data was copied or entered accurately, often by comparing copies. Authentication checks identity or credentials. A validly shaped ID can still belong to somebody else.
A program checks that an entered email field is not blank. What has it established?
- AThe address belongs to the user.
- BThe address can receive messages.
- CSome input is present, but its truth is not proven.
- DThe user has been authenticated.
Route forward
You can select and construct the four required validation checks, including repeated prompting. Next you will search a list systematically and record evidence about comparisons.