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. Once the WHILE check has run, which line do you think comes next?
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 input against set rules before it's used. In a program, a validation routine is the code that does it.
- Catching bad input makes the program more robust: it avoids errors and wrong results.
- A routine is a loop with selection: ask for input, then WHILE it breaks a rule, show an error message and ask again.
- So the WHILE condition is true for bad input, like age < 0 OR age > 120. Valid input ends the loop.
Have a goYour condition is age < 0 OR age > 120, and the user types 150. Is the condition true or false, and does the loop run?
True, so the loop runs.
150 is above 120, and one broken rule is enough to make the whole OR true. Valid input would make it false and end the loop.
- Inside the loop: a message saying what's wanted, then a new input. Skip the new input and the loop never ends.
- Presence check: has anything been entered? Type check: is it the right kind of data, such as a whole number?
Have a goYour mate types 'banana' into an age box and swears it's fine because it's definitely something. Which check says no?
The type check.
'banana' is something, so a presence check lets it through, but it isn't the right kind of data for an age.
- Range check: is it between the limits? Length check: an allowed number of characters? Format check: does it follow the pattern?
- Normal test data is typical and accepted. Boundary data sits either side of an edge: the edge value is accepted, the value just past it is rejected.
Have a goA lift takes 1 to 8 people. Pick two values that test the top edge, and say what should happen to each.
8 is accepted; 9 is rejected.
8 is right on the edge so it's allowed, and 9 is just past it. A condition with its edge in the wrong place only gives itself away here.
- Erroneous data is plainly wrong, such as the wrong type of data, and should be rejected.
- 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. Spreadsheets and online forms do it too, with rules on things like text, dates and number ranges. 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
(15)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?
What should a WHILE validation condition describe?
Why show a helpful error message?
Where else is validation used, and what can its rules be about?
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
- Concept of a data type
- Concept of subroutines
- Constant declaration
- Convert character code to character
- Convert character to character code
- Correcting errors
- Equal to (relational operator)
- Greater than (relational operator)
- Greater than or equal to (relational operator)
- Identifying and categorising errors
- Indefinite (condition-controlled) iteration
- Integer / real to string conversion
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 24 October 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.