Computer ScienceExam code: 0984

Problem Solving and Design

Algorithm Design and Problem Solving

Validation is an automated check carried out by the program that an input is plausible and obeys the rules of the field it belongs to, applied the moment the data is entered.

Validation cannot guarantee that an input is correct (no program can tell whether a typed name is really the user's name). It can only guarantee that the input is plausible. A well-validated form accepts everything that is plausible and rejects everything that is obviously wrong.

Login form rejecting an implausible email entry, showing a red error message asking the user to check the email and try again
Source: Validation in Computer Science by Save My Exams

The syllabus names six validation checks you should know.

Range check

Tests that a number falls within a specified range.

Length check

Tests that a string has the right number of characters.

Type check

Tests that the input is of the expected data type (integer, real, string, boolean, etc.).

Presence check

Tests that a value has actually been entered (the field is not blank).

Format check

Tests that the input matches a specific pattern.

Check digit

An extra digit appended to a numerical code (e.g. ISBN, barcode) that is calculated from the other digits and used to detect errors when the code is entered.

Check digits were covered in detail in topic 5 (Error Detection); the same idea is reused as a validation method on input forms.

Combining validation checks

A single field may need several validation checks at once. A password field might use a length check (at least 8 characters), a presence check (not blank), and a format check (must contain a letter and a digit). Each check rules out one kind of invalid input.

Common exam question

Naming the validation check for a described rule

Question: State or tick the validation check for a described rule, match descriptions to checks, or describe the checks a program needs for its input rules (1–4 marks).

Asked in 6 of the 17 papers. Use the exact names: range check (a value between two limits), format check (a dd/mm/yyyy date, an email address with an @ sign), presence check (something has been entered), type check (an integer was entered; "character check" is also credited), length check (the right number of characters), check digit (an identification number has no errors).

Describing the checks for a set of rules earns one mark per check, named with what it tests: a range check with its limits, a presence check for a blank entry, a type check so a number is entered, a length check capping the digits (on a dd/mm/yyyy date, it counts 10 characters and rejects other lengths). Double entry and visual checks are tick-box distractors: they are verification, not validation.

Quick check

4 short questions on this note. See what has stuck, and where to look if something hasn't.

About 2 minutes

Build on this topic