The shape of the lesson
By the end of the lesson, learners can
- Six validation checks: Type different values into the validation tab of the lab and see which check accepts or rejects each one.
- Check digits: A check digit is an extra digit worked out from the other digits and added to the end.
- Verification: entered as intended: Data can pass every validation check and still be wrong: a date of birth of 12/03/2009 typed instead of 21/03/2009 is perfectly sensible.
- Validation (automatic): range, length, type, presence, format, check digit.
- Verification: visual check, double entry check.
- Describe a check: say what it tests and give an example from the question's context.
- Write a check: input, test the rule, error message, input again until valid.
One picture every idea returns to
Validation is an automatic check by the computer that input data is sensible and allowed before it is accepted: range, length, type, presence, format and check digit checks. Verification checks that data has been entered accurately, matching the original: a visual check or a double entry check. Validation cannot prove data is correct, only that it is reasonable.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Sensible is not the same as correct.. Programs must not accept nonsense such as an age of 250 or an empty name. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Six validation checks | Type different values into the validation tab of the lab and see which check accepts or rejects each one. Project tab 3 of the lab (Validation checks) and let a student drive it while the class predicts. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Check digits | A check digit is an extra digit worked out from the other digits and added to the end. Model the worked example ISBN-13 check digit on the board, one line at a time. Your turn: Calculate the ISBN-13 check digit for 978014103614. | Pairs |
| 21 to 30 min | Teach and check: Verification: entered as intended | Data can pass every validation check and still be wrong: a date of birth of 12/03/2009 typed instead of 21/03/2009 is perfectly sensible. | Cooperative Concept Mapping |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 17 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Verification: entered as intended, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Cooperative Concept Mapping
Teams receive the key terms on cards and arrange them on a large sheet, drawing and labelling the links. Compare maps between teams before showing the model map.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| A range check is about the value (13 is too big); a length check is about the number of characters ("abc" is too short). | Name the check that matches the rule in the question. |
| A check digit is a validation check (it is calculated automatically), even though it catches typing mistakes. | It cannot tell you whether the number is the right book, only that the digits are consistent. |
| Validation and verification are not interchangeable. | Validation: is the data reasonable? Verification: is it the same as the original? Neither guarantees the data is true. |
Validation and verification checks: worksheet
6 questions, 17 marks. Written in the style of the papers; no past paper question is reproduced.
Explain why validation checks are needed on input data.
A sign-up form asks for a username (6 to 12 characters), an age (13 to 99) and an email address. Identify a suitable validation check for each, and one more check that applies to all three fields.
An ISBN-13 is entered as 9781234567896. Use the check digit method (weights 1 and 3, sum MOD 10, subtract from 10) to show that it has been entered incorrectly.
Write pseudocode to input a percentage and use a range check so that only values from 0 to 100 inclusive are accepted. An error message must be output for each invalid value.
Describe how a double entry check works.
A student's date of birth is entered as 14/07/2010 instead of 17/04/2010. Explain why a format check does not detect this error, and name a check that could.
Answer key and marking notes
- To make sure only sensible / reasonable data that meets the rules is accepted.
- So that impossible or unreasonable data is rejected before it is processed or stored (reducing errors in the output).
- Username: length check (6 to 12 characters).
- Age: range check (13 to 99) or type check (integer).
- Email: format check (contains @ and a full stop in the right places).
- All three: presence check (none may be left empty).
- Weighted sum of the first 12 digits: 9 + 21 + 8 + 3 + 2 + 9 + 4 + 15 + 6 + 21 + 8 + 27 = 133.
- 133 MOD 10 = 3; 10 − 3 = 7.
- The calculated check digit 7 does not match the entered digit 6, so there is an error.
- Prompt and INPUT Percentage.
- Loop (WHILE or REPEAT) while Percentage < 0 OR Percentage > 100.
- Output an error message inside the loop.
- INPUT Percentage again inside the loop, so the loop ends when the value is valid.
- The data is entered twice (e.g. a new password typed twice).
- The computer compares the two entries; if they do not match, the data is rejected and must be entered again.
- The wrong date still has the correct DD/MM/YYYY format (and is a possible date), so it passes the format check.
- A verification check: a visual check against the original document (or double entry).
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
A mobile phone number must be entered as exactly 11 characters. Which validation check tests this rule?
- Alength check
- Brange check
- Cpresence check
- Dtype check
Which of these is a verification check?
- AA clerk compares the postcode on screen with the paper form
- BThe program rejects a postcode that does not contain a space
- CThe program rejects a form with the postcode field left empty
- DThe program rejects a postcode longer than 8 characters
The ISBN-13 check digit is found by multiplying the first 12 digits alternately by 1 and 3, adding the products, finding the sum MOD 10 and subtracting the result from 10 (a result of 10 gives 0). What is the check digit for 978030640615?
- A7
- B3
- C1
- D9
Which type of validation check does this pseudocode carry out?
REPEAT
OUTPUT "How many items? (1 to 20)"
INPUT Quantity
UNTIL Quantity >= 1 AND Quantity <= 20- Arange check
- Blength check
- Cpresence check
- Ddouble entry check
A product number is six digits followed by a seventh digit, a check digit. Which input error would the check digit detect that a format check would not?
- Atwo neighbouring digits typed the wrong way round
- Ba letter typed in place of one of the digits
- Cthe product number field left completely empty
- Dthe correct number of a different product
This range check is run and the user types 0, then 7, then 6, then 2. How many times is the error message output, and which value of Tickets is accepted?
REPEAT
OUTPUT "Enter the number of tickets (1 to 6)"
INPUT Tickets
IF Tickets < 1 OR Tickets > 6
THEN
OUTPUT "Error: enter a number from 1 to 6"
ENDIF
UNTIL Tickets >= 1 AND Tickets <= 6- A2 error messages; 6 is accepted
- B2 error messages; 2 is accepted
- C3 error messages; 2 is accepted
- D1 error message; 7 is accepted
Quiz key
A length check tests the number of characters, here exactly 11. A range check tests that a value lies between two limits, which is not how a phone number is checked. A presence check only tests that something has been entered, and a type check tests the data type, so neither would reject a 10-character number.
Comparing the entered data with the original document is a visual check, a form of verification. Rejecting a postcode without a space is a format check, an empty field is caught by a presence check and more than 8 characters by a length check: these are all automatic validation checks.
Weighted sum: 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15 = 93. 93 MOD 10 = 3 and 10 - 3 = 7. Giving 3 forgets to subtract from 10. Adding the digits without the weights gives 49, so 1 (after subtracting) or 9 (without subtracting) both come from leaving out the weights.
Testing that Quantity lies between 1 and 20 is a range check. A length check would use LENGTH to count characters, a presence check would test for an empty input, and a double entry check (verification) would compare two inputs of the same data.
Swapping two digits keeps the format (seven digits) so a format check accepts it, but the recalculated check digit no longer matches. A letter instead of a digit breaks the format, so the format check already catches it. An empty field is caught by a presence check (and fails the format). A valid number for the wrong product passes both checks, because it is consistent; only verification against the source could catch it.
0 is below 1 and 7 is above 6, so each gives an error message. 6 is within 1 to 6 (the limit is included), so the UNTIL condition is true and the loop ends with 6 accepted; the 2 is never read. Accepting 2 or counting 3 errors treats 6 as invalid. 7 is outside the range, so it cannot be accepted.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.