7.5 Validation and verification

← Topic 7.4 Standard methods of solutionComputer Science contentsTopic 7.6 Test data →
Chapter 7 · Algorithm design and problem solving

7.5 Validation and verification

Before data is accepted by a computer system, it may need to be checked. Topic 7.5 separates two ideas that sound similar but do different jobs: validation checks whether entered data is reasonable, while verification checks whether data has been copied accurately from one source to another.

ValidationRange / length / typePresence / formatCheck digitsVerification

Validation and verification are not the same

MethodWhat it checksTypical use
ValidationWhether entered data is reasonable according to rules set by the program.Checking a mark is within an allowed range or a required field is not blank.
VerificationWhether data has been copied accurately from one source to another.Entering the same data twice or visually checking entered data against the original source.
Core distinction: validation checks reasonableness; verification checks accuracy of copying.
Check the difference before moving on.

7.5.1 Validation

Validation is an automatic check performed by a program before data is accepted. If a value fails a validation rule, the system should reject it, explain the problem and give the user another opportunity to enter the data.

The textbook identifies six validation methods that you should recognise:

Validation checkWhat it checks
Range checkA number lies between allowed lower and upper limits.
Length checkData contains an exact, minimum or maximum acceptable number of characters.
Type checkThe entered value is of the required data type.
Presence checkA required item has actually been entered and is not blank.
Format checkCharacters follow a required pattern.
Check digitA calculated final digit is used to detect common entry or scanning errors in a code.

More than one validation rule can be applied to the same item. For example, an examination mark can be checked with a range check, a type check and a presence check.

Range check

A range check tests whether a numeric value falls between a lower and upper limit. For a percentage mark, only values from 0 to 100 inclusive should be accepted.

Example: validate a percentage mark

OUTPUT "Please enter the student's mark"
REPEAT
  INPUT StudentMark
  IF StudentMark < 0 OR StudentMark > 100
    THEN
      OUTPUT "Mark must be from 0 to 100. Please re-enter."
  ENDIF
UNTIL StudentMark >= 0 AND StudentMark <= 100

The loop keeps requesting input until the mark is inside the permitted range.

Length check

A length check examines how many characters are present. It can require an exact length or an acceptable range of lengths.

Example: password of exactly eight characters

OUTPUT "Enter an eight-character password"
REPEAT
  INPUT Password
  IF LENGTH(Password) <> 8
    THEN
      OUTPUT "Password must contain exactly eight characters."
  ENDIF
UNTIL LENGTH(Password) = 8

LENGTH() returns the number of characters in a string. The textbook also gives the example of a family name that must contain between 2 and 30 characters inclusive.

Type check

A type check checks whether the value has the required data type. The textbook example asks for the number of brothers, which should be an integer rather than a fractional value.

Example: require a whole number

OUTPUT "How many brothers do you have?"
REPEAT
  INPUT NumberOfBrothers
  IF NumberOfBrothers <> DIV(NumberOfBrothers, 1)
    THEN
      OUTPUT "This must be a whole number. Please re-enter."
  ENDIF
UNTIL NumberOfBrothers = DIV(NumberOfBrothers, 1)

Presence check

A presence check makes sure a required field is not left blank. An online transaction, for example, may require an email address before it can continue.

Example: required email address

OUTPUT "Please enter your email address"
REPEAT
  INPUT EmailAddress
  IF EmailAddress = ""
    THEN
      OUTPUT "*=Required"
  ENDIF
UNTIL EmailAddress <> ""
Figure 7.12 showing a presence check error message on a required email field
Figure 7.12 Presence check error message
Check range, length, type and presence validation.

Format check

A format check checks that characters match a pre-defined pattern. A code might, for example, require three letters followed by three digits. The check is concerned with the pattern used, not simply the number of characters.

Check digit

A check digit is an additional digit calculated from the other digits in a code. It is widely used in barcodes, product codes, ISBNs and Vehicle Identification Numbers (VINs).

Its purpose is to identify common errors caused by typing or scanning. The source states that a check digit can usually detect:

Figure 7.13 showing an ISBN 13 barcode and its check digit
Figure 7.13 ISBN 13 code with check digit
Remember: a check digit is calculated from the other digits. When the code is entered or scanned, the calculation can be repeated and compared with the stored check digit.
Check format checks and check digits.

7.5.2 Verification

Verification checks that data has been copied accurately from one source to another. This can apply when data is entered into a computer or when it is transferred from one part of a computer system to another.

For input data, the textbook identifies two verification methods:

MethodHow it works
Double entryThe data is entered twice, sometimes by different operators. The computer compares the two entries. If they differ, an error message is produced and the data must be entered again.
Screen/visual checkThe entered data is displayed and the user manually checks it against the original source or against what they know to be correct before confirming it.

Double entry

Figure 7.14 showing double entry of an email address and password
Figure 7.14 Double entry

Double entry is useful because the computer can automatically compare both versions. If the two copies do not match, it knows that at least one entry differs and can request re-entry.

Screen/visual check

A screen or visual check is completed by the person entering the data. After entry, the system displays the data so the user can compare it with a paper form or confirm it using their own knowledge.

Related data-transfer checks: the source links verification during transfer to parity checks and checksums, which are covered in Chapter 2 rather than developed further in Topic 7.5.
Check the two input-verification methods.

Topic 7.5 revision checklist

State that validation automatically checks whether data is reasonable before it is accepted.
State that verification checks whether data has been copied accurately from one source to another.
Explain the difference between validation and verification.
Explain and apply a range check.
Explain exact-length and acceptable-length checks.
Explain a type check.
Explain a presence check.
Explain a format check.
Explain what a check digit is and the types of entry errors it can detect.
Recognise that several validation checks may be used on the same data item.
Explain double-entry verification.
Explain a screen/visual verification check.
Ready for a mixed Topic 7.5 check?
← Topic 7.4 Standard methods of solutionComputer Science contentsTopic 7.6 Test data →