GCSE · Computer Science · AQA · Spec 8525
Data validation routines
Type 150 into an age box and a good program won't argue. It just asks again, and again, until you give it something sensible. That stubbornness has a name.
Computer Science · Programming
The routine that won't take no for an answer
One real run: a wrong answer, then a blank, then a good one. Watch where the program goes after each ENDWHILE.
Before you press Next: the first answer is 150. Which line do you think runs after the check on line 3?
1 OUTPUT "Enter your age (0 to 120)"2 age ← USERINPUT3 WHILE age = "" OR age < 0 OR age > 1204 OUTPUT "Please type an age from 0 to 120"5 age ← USERINPUT6 ENDWHILE7 OUTPUT "Thanks, age saved"
Variables
Output
Enter your age (0 to 120)
Step 1: The program asks the question. Nothing is stored in age yet.
Press Next to run one line at a time. The green line is the one running now.
Computer Science · Validation checks
Which check catches it?
Each input below breaks exactly one rule. Pick an input, then pick the check that catches it.
Still to sort
Presence check (0)
Has anything been entered at all?
Where the line is: Presence only asks whether something is there. It doesn't care what it is.
Type check (0)
Is it the right kind of data, such as a whole number rather than text?
Where the line is: Type is about the kind of data. Format is about the pattern its characters follow.
Range check (0)
Is the value between the lower and upper limits?
Where the line is: Range checks the size of a value. Length checks how many characters it has.
Length check (0)
Does it have an allowed number of characters?
Where the line is: Length counts characters. It doesn't look at what the characters are.
Format check (0)
Does it follow the required pattern, such as DD/MM/YYYY?
Where the line is: Format checks the shape only. Data can have the right shape and still hold an impossible value.
The routine you just stepped through used two checks. There are five you should know by name.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A validation routine is a bouncer at the door: it keeps sending you back until your input follows the rules. Following the rules isn't the same as being true, though.
What you need to know
- Data validation checks that input is sensible and follows set rules before the program uses it. Online forms and spreadsheets validate data too.
- A validation routine uses a loop such as WHILE. Its condition is true while the input breaks a rule, so the program keeps asking until the input is valid.
- Inside the loop, output an error message that says what's wanted, then take a new input. Without the new input the condition never changes and the loop never ends.
- Presence check: has something been entered? Type check: is it the right kind of data? Range check: is it between the limits? Length check: does it have an allowed number of characters? Format check: does it follow the required pattern?
- Test data comes in three kinds. Normal data is typical and should be accepted. Boundary data sits either side of an edge of the allowed range: the value right on the edge should be accepted, and the value just past it should be rejected. Erroneous data should be rejected, for example the wrong type of data.
- Validation can't prove data is correct. A real age of 16 typed as 15 still passes every check.
The big picture
Data validation checks that input is sensible and follows set rules before a program uses it. A validation routine is a loop: it takes an input, checks it, shows a helpful error message if a rule is broken, and asks again. It only moves on once the input is valid. The common checks are presence, type, range, length and format. You prove a routine works with normal, boundary and erroneous test data. Validation catches nonsense, but it can't guarantee that data is correct.
Key points
Worked example
Problem
A cinema's booking program asks how many tickets you want. It accepts whole numbers from 1 to 10. Choose test data that would prove its validation routine works, and say what should happen for each value.
⚠ Watch out
Writing the loop condition for good input instead of bad. WHILE age >= 0 AND age <= 120 keeps asking when the age is fine, and lets 150 straight through. The WHILE condition has to be true for the input you want to reject.
Memory hook
Picture a bouncer with a rule list: no blank names, no ages over 120. The bouncer keeps sending you to the back of the queue until you meet every rule. But the bouncer only checks the rules. Whether you're telling the truth is something no rule list can check.
Check yourself
A quiz app accepts scores from 0 to 50. Write the WHILE line that keeps asking while the score is out of range. Why must 50 be one of your test values?
Flashcards
(12)What does data validation check?
Why does a validation routine need a loop rather than a single IF?
What two things go inside a validation loop?
Presence check
Type check
Range check
Length check
Format check
Normal test data
Boundary test data
Erroneous test data
Can data that passes validation still be wrong?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.