Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Defensive Design

Input validation

2.3.1 Defensive Design

Practise exam questions

Defensive Design — Note 2 of 3

Practical experience of designing input validation and simple authentication (e.g. username and password)

What you need to know

Input validation checks that data entered by a user is reasonable and appropriate before the program processes it. Common types include presence checks (data was entered), range checks (value falls within limits), length checks (correct number of characters), type checks (correct data type), and format checks (correct pattern).

What to know

  • Validation does NOT check if data is CORRECT, only that it is reasonable and in the right format.
  • Validation is usually implemented using loops (while) that keep asking until valid data is entered.
  • An existence check is the same idea as a look-up check: the input must match one of a list of allowed values.
  • The presence, range, length and look-up examples check the input once. To keep asking until the input is valid, put the check in a while loop.

Code examples

Input validation examples (OCR Exam Reference Language)
text
// Range check
num = int(input("Enter a number 1-10: "))
while num < 1 OR num > 10
    print("Out of range!")
    num = int(input("Enter a number 1-10: "))
endwhile

// Presence check
name = input("Enter your name: ")
while name == ""
    name = input("Name cannot be blank: ")
endwhile

// Length check
password = input("Enter password (min 8 chars): ")
while password.length < 8
    password = input("Too short! Try again: ")
endwhile
Input validation examples
python
# Range check
num = int(input("Enter a number 1-10: "))
while num < 1 or num > 10:
    print("Out of range!")
    num = int(input("Enter a number 1-10: "))

# Presence check
name = input("Enter your name: ")
while name == "":
    name = input("Name cannot be blank: ")

# Length check
password = input("Enter password (min 8 chars): ")
while len(password) < 8:
    password = input("Too short! Try again: ")
Presence, range, length and look-up checks (OCR Exam Reference Language)
text
// Presence check: something must be entered
name = input("Enter your name: ")
if name == "" then
    print("You must enter a name.")
endif

// Range check: value must be inside the allowed limits
age = int(input("Enter your age: "))
if age >= 0 AND age <= 120 then
    print("Valid age")
endif

// Length check: minimum number of characters
password = input("Enter password: ")
if password.length < 8 then
    print("Too short")
endif

// Look-up (existence) check: value must be in a list
array items = ["pen", "pencil", "ruler"]
item = input("Enter an item: ")
found = False
for i = 0 to 2
    if items[i] == item then
        found = True
    endif
next i
if NOT found then
    print("Item not recognised")
endif
Presence, range, length and look-up checks
python
# Presence check: something must be entered
name = input("Enter your name: ")
if name == "":
    print("You must enter a name.")

# Range check: value must be inside the allowed limits
age = int(input("Enter your age: "))
if age >= 0 and age <= 120:
    print("Valid age")

# Length check: minimum number of characters
password = input("Enter password: ")
if len(password) < 8:
    print("Too short")

# Look-up (existence) check: value must be in a list
items = ["pen", "pencil", "ruler"]
item = input("Enter an item: ")
found = False
for i in range(len(items)):
    if items[i] == item:
        found = True
if not found:
    print("Item not recognised")

Key terms

Range check

Ensures a value falls within an acceptable range, for example shoeSize >= 1 AND shoeSize <= 13.

Presence check

Ensures data has been entered and is not blank (for example postcode != "").

Length check

Ensures the input has the correct number of characters, for example code.length == 3.

Type check

A validation check that ensures data is of the correct data type (for example integer or string).

Format check

A validation check that ensures data follows a specific pattern or structure (for example DD/MM/YYYY).

Look-up check

A validation check that compares input data against a predefined list of valid values.

Exam technique

  • Tip:When checking MULTIPLE validations, all must pass for the input to be accepted, and any failure means it is rejected. Use a Boolean flag (for example valid = True) and set it to False if any check fails.
  • Tip:In range checks, you must compare the variable in BOTH parts: if laps >= 2 AND laps <= 30. NOT: if laps >= 2 AND <= 30 (missing variable reference). For an inclusive range use >= and <=: laps > 2 AND laps < 30 wrongly rejects 2 and 30.
  • Tip:Use >= and <= in code, NOT the maths symbols ≥ or ≤ (not available on a keyboard). Also =< is WRONG — must be <=.
  • Mistake:if seat == "window" OR "aisle" is WRONG. You must compare the variable each time: if seat == "window" OR seat == "aisle". Keep the quotes too: without them, window and aisle are treated as variable names, not text.
  • Mistake:if seat != "window" OR seat != "aisle" is ALWAYS True (any value will fail one test). Use AND: if seat != "window" AND seat != "aisle".
  • Tip:Name the validation type AND explain HOW it applies to the scenario. For example, 'Range check — make sure the number of laps entered is from 2 to 30'. Only validate inputs the program actually takes; 'check the data is valid' on its own scores nothing.
  • Tip:Validation only applies to USER inputs. Do not validate randomly generated values.

Ready to test yourself?

Practise 2.3.1 questions
← Previous noteAnticipating misuse, Authentication2.3.1 Defensive DesignNext note →Use of sub programs; Naming conventions; Indentation; Commenting2.3.1 Defensive Design

Back to Defensive Design

Revise another OCR GCSE topic: Testing

Defensive Design

Note 2 of 3

  1. 1Anticipating misuse, Authentication
  2. 2Input validation
  3. 3Use of sub programs; Naming conventions; Indentation; Commenting
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).