Choosing a validation check for each field

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Choosing a validation check for each field

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which validation check best fits a Mark field that must be between 0 and 100?
A Range check
B Presence check
2. A PhoneNumber field must always contain exactly 10 digits. Which check fits best?
A Length check
B Range check
3. The FirstName field must not be left empty when a new student is added. Which check fits best?
A Length check
B Presence check
4. A YearGroup field may only contain 7, 8, 9, 10 or 11. Which check fits best?
A List check
B Presence check
5. An Age field for students in a school must be between 11 and 18. Which check is the best choice?
A List check
B Range check

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Range check: Mark >= 0 AND Mark <= 100 AA length check tests the number of characters, so it cannot stop 3 or 14 being entered. A list check against the valid year groups is better.
2Length check: LENGTH(Phone) = 11 BYearGroup IN (7, 8, 9, 10, 11)
3A Name field is required, so the record must not be saved with it empty. Use a presence check. CChecks the data has exactly the right number of characters, so it fits a phone number
4A YearGroup field can only hold a few fixed values, so check it against an allowed list. DA presence check only confirms that something was typed, so it would accept a mark of 500. A range check from 0 to 100 should be used.
5Validation for Mark: presence check EChecks a number lies between a lowest and highest allowed value, so it fits a test mark or an age
6Validation for YearGroup: length check FName <> ''

Definitions

validation check

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Mark: _____ check, between 0 and 100
2.
Phone: ______ check, must be 10 characters
3.
FirstName: ________ check, cannot be empty
4.
YearGroup: ____ check, only 7, 8, 9, 10, 11
5.
IF ______(Phone) = 10 THEN ACCEPT

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Field: Mark (integer)
B Check: length check
C Rule: 0 <= Mark <= 100
Question 2
A IF LEN(Phone) = 11 THEN
B OUTPUT "Must be 11 digits"
C ENDIF
Question 3
A Field: FirstName
B Check: presence check
C Rule: FirstName = ""
Question 4
A Field: YearGroup
B Check: presence check
C Rule: IN (7, 8, 9, 10, 11)
Question 5
A Field: Age
B Check: length check
C Rule: Age >= 11 AND Age <= 16
D Reject if outside range

Answer Key

Choosing a validation check for each field
Section A: Quick Questions
Q1
A — Range check
Q2
A — Length check
Q3
B — Presence check
Q4
A — List check
Q5
B — Range check
Section B: Match the Pairs
Q1
Range check: Mark >= 0 AND Mark <= 100 → Checks a number lies between a lowest and highest allowed value, so it fits a test mark or an age
Q2
Length check: LENGTH(Phone) = 11 → Checks the data has exactly the right number of characters, so it fits a phone number
Q3
A Name field is required, so the record must not be saved with it empty. Use a presence check. → Name <> ''
Q4
A YearGroup field can only hold a few fixed values, so check it against an allowed list. → YearGroup IN (7, 8, 9, 10, 11)
Q5
Validation for Mark: presence check → A presence check only confirms that something was typed, so it would accept a mark of 500. A range check from 0 to 100 should be used.
Q6
Validation for YearGroup: length check → A length check tests the number of characters, so it cannot stop 3 or 14 being entered. A list check against the valid year groups is better.
Section C: Definitions
Q1
validation check — A rule that tests data on entry. Pick the one that fits each field: range for a mark, length for a phone number, presence for a required name, list for a year group.
Section D: Fill in the Blanks
Q1
Mark: range check, between 0 and 100
Q2
Phone: length check, must be 10 characters
Q3
FirstName: presence check, cannot be empty
Q4
YearGroup: list check, only 7, 8, 9, 10, 11
Q5
IF LENGTH(Phone) = 10 THEN ACCEPT
Section E: Spot the Error
Q1
B — A mark is a number that must fall between limits, so it needs a range check. A length check counts characters and does not test the size of a value. It should be 'Check: range check'.
Q2
A — A length check should reject a phone number whose length is wrong. Using = would show the error for valid numbers. It should be IF LEN(Phone) <> 11 THEN.
Q3
C — A presence check makes sure a required field is not empty. Using = "" would only accept an empty name. The rule should be FirstName <> "".
Q4
B — A presence check only tests that something was entered, so a wrong year such as 12 would still pass. A year group must be one of a fixed set of values, so use a list check.
Q5
B — The rule tests that Age lies between 11 and 16, which is a range check. A length check only counts characters, so it would accept an age such as 99. It should be 'Check: range check'.