Learning Objectives
  • Explain why input data is validated.
  • Describe and apply range, length, type, presence, format and check-digit checks.
  • Select suitable validation checks for a scenario.
  • Explain why validation does not prove that data is correct.
Key Terms
Validation
Automatic checking that input data is reasonable and follows defined rules.
Range check
Checks that a value lies within stated limits.
Length check
Checks the number of characters or items.
Type check
Checks that data is of the required type.
Presence check
Checks that required data has been entered.
Format check
Checks that data follows a required pattern.
Check digit
An extra digit calculated from other digits and used to detect likely entry errors.
Summary diagram
Summary Of The Main Ideas In This Lesson
Purpose And Limitation

Validation reduces the chance that unsuitable data enters a system. It compares input with rules chosen during analysis. Invalid data is rejected or causes an error message.

Validation does not prove that data is true. An age of 25 may pass a range check even if the persons real age is 24. It only shows that the entered value is plausible according to the rule.

Range Check

A range check tests upper and lower limits. A mark may be accepted when 0 <= Mark <= 100. The limits may be inclusive or exclusive, so the condition must follow the wording exactly.

A range check is suitable for numerical or date values with meaningful bounds. It is not the same as checking the number of characters.

Length, Type And Presence Checks

A length check can require exactly eight characters, no more than 20 characters or at least one character. A type check ensures data such as an integer or date is entered in a form the system can process.

A presence check ensures a required field is not empty. It does not check whether the entered content is meaningful or correctly formatted.

Format Check

A format check tests a pattern, such as two letters followed by four digits. A value can have the correct length but the wrong format, so both checks may be useful.

The rule should describe positions or separators clearly. For example, a date may require DD/MM/YYYY. A format check alone does not prove the date exists unless additional checks are applied.

Check Digit

A check digit is calculated from the other digits in a code. When the code is entered, the calculation is repeated and compared with the supplied check digit. A mismatch suggests that one or more digits were entered incorrectly.

Topic 2 explains the use of check digits in data entry. In Topic 7, students should be able to recognise and apply check-digit validation as part of an algorithm. A check digit detects likely errors; it does not authenticate the owner or guarantee that the code belongs to the correct item.

Selecting A Check
Data Requirement Suitable Check
Age must be 12 to 18 inclusive Range
Password must contain at least 10 characters Length
Quantity must be an integer Type
Email field cannot be empty Presence
Code must be two letters followed by four digits Format
Product barcode includes a calculated final digit Check digit
Worked Examples
Student Registration

Question: Suggest validation for age, student code and surname.

  1. Age 11 to 19: range check.
  2. Student code exactly eight characters: length check.
  3. Student code pattern two letters and six digits: format check.
  4. Surname required: presence check.

Answer: Several checks can be applied to one field because each tests a different rule.

Plausible But Wrong

Question: A user enters age 17 instead of 16. A range check accepts 17. Has validation failed?

  1. The rule checks whether the value is in the permitted range.
  2. 17 is in that range.
  3. The system cannot know the persons real age from the range rule.

Answer: The validation worked as defined, but it cannot prove factual correctness.

Examination Guidance
  • Name the check and explain the exact rule in context.
  • Use inclusive or exclusive limits accurately.
  • Do not claim validation ensures correctness.
  • Recognise that several checks may be needed for one field.
  • For format checks, state the required pattern rather than only “correct format.”
Common Mistakes
  • Calling a range check a length check.
  • Using a presence check to claim that data is accurate.
  • Assuming a check digit encrypts data.
  • Forgetting to repeat input or produce an error after rejection.
  • Applying a numerical range rule to a text pattern.
Knowledge Check

1. What is validation?

Answer: Checking that input data follows defined rules and is reasonable for the system.

2. What does a range check test?

Answer: Whether a value lies within permitted limits.

3. What does a presence check test?

Answer: Whether required data has been entered.

4. Can validation prove data is true?

Answer: No; plausible but incorrect data may pass.

5. What is a check digit used for?

Answer: To detect likely errors in an entered numerical code.