Community resourceWorksheet
J277 2.3.1 Input validation methods
Part 2 of 7 · J277 2.3 · Producing robust programs
The validation methods OCR expects, and how to apply one to the input a question actually describes.
Students will:
- name the common validation methods and what each checks
- choose a suitable method for a stated input
- explain a method against the scenario rather than in general
- explain what validation does not prove
- describe what a program should do with invalid data
Inside: 5 explanation cells, 3 multiple-choice questions, 1 fill-in-the-blanks cell and 3 written answers. 22 marks, about 45 minutes.
Series: J277 2.3 · Producing robust programs, part 2 of 7.
Shared by Coding PathwayVerified teacher
- 12 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
- Updated 9 Sept 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Input validation methods
Validation checks whether input meets stated acceptance rules before a program uses it. If the input is invalid, a robust program should reject it, explain the problem clearly and allow a suitable correction.
Validation does not prove that entered data is true. An age of 15 may pass a range check even if the user is actually 16. Validation only shows that the value follows the rules the programmer has chosen.
OCR questions often ask you to identify a suitable validation method and explain how it applies to a scenario. The scenario matters: “a range check checks a range” is too vague to earn an explanation mark.
Common validation methods
| Method | What it checks | Example use |
|---|---|---|
| Range check | A number is within permitted minimum and maximum values. | A ticket quantity is from 1 to 8 inclusive. |
| Type check | Data has the required data type. | A quantity is a whole number. |
| Presence check | A required value has not been left empty. | A contact name has been entered. |
| Length check | Text has an acceptable number of characters. | A club code contains exactly six characters. |
| Format check | Data follows a required pattern. | A date follows DD/MM/YYYY. |
| Lookup check | A value appears in an accepted list or table. | An event code is one of ART, CODE or MUSIC. |
Different checks can be combined. For example, a six-character event code could need both a length check and a lookup check.
- range
- presence
- lookup
- format
- length
- type
A school event code must be exactly six characters long. Which validation method directly checks this rule?
- APresence check
- BRange check
- CLength check
- DType check
A booking must use one of the codes ART, CODE or MUSIC and must not be left empty. Choose two appropriate validation methods.
- ALookup check
- BPresence check
- CRange check
- DType check
Apply the rule to the actual input
Imagine a mental-maths game that displays two random whole numbers from 1 to 12 and asks the player to enter their total. The player's total is the input being validated. The random numbers are generated by the program, so validating those is not the answer to the question.
The smallest possible total is 2 and the largest is 24. A range check on the player's answer could therefore reject totals below 2 or above 24. A type check could ensure the answer is a whole number.
This is an important exam habit: identify exactly which value the user enters, then apply the validation rule to that value.
A geography quiz displays two numbers from 5 to 20 and asks the player to enter their sum. Identify two validation methods and explain how each could be applied to the player's answer.
For each method, name it, state the exact rule and explain what unsuitable input it rejects. The possible answer is from 10 to 40 inclusive.
Students type their answer here.
What should happen to invalid data?
A check is useful only if the program responds appropriately. A clear pattern is:
- receive the input;
- test it against the acceptance rule;
- if it is invalid, display a helpful message and request a replacement;
- continue only when an acceptable value has been received.
Silently changing an answer or continuing with invalid data can create unexpected results. The message should tell the user what rule to follow, such as “Enter a whole number from 1 to 8”.
Which response is most useful when a ticket quantity of 12 is rejected because only 1 to 8 tickets are allowed?
- AContinue with 12 and hope enough tickets remain
- BReplace 12 with 1 without telling the user
- CStop the entire system without an explanation
- DDisplay `Enter a whole number from 1 to 8` and ask again
Explain why passing validation does not guarantee that input is correct.
Use one example of a value that follows a rule but may still be factually wrong.
Students type their answer here.
A youth theatre registration form requires a stage name, an age from 11 to 18, and a selected workshop code from ACT, LIGHT or SOUND. Recommend three validation checks and justify each choice.
Apply one check to each field. Use field, rule, rejected input as the structure for each point.
Students type their answer here.
Review
Without looking back, list the six validation methods and give one new example of any three. Then answer this final distinction: validation checks input during use, while testing is a development activity used to discover whether a program behaves as expected. The testing worksheets will return to this difference.