7 Algorithm design and problem-solving

Show All Section Notes

Validation and Verification Checks

1. Why Check Input Data At All?

Programs cannot assume that the data entered is sensible. Users mistype, misread instructions, or deliberately enter nonsense. If bad data reaches the processing stage, the output is wrong — and the program may crash.

Two different jobs, often confused:
Validation asks “is this data reasonable?” — done automatically by the program.
Verification asks “has this data been copied or typed accurately?” — checks for mistakes during entry.

The distinction matters because a value can pass one and fail the other. A date of birth of 14/07/2009 is perfectly valid — but if the student was actually born in 2010, it is not verified. Validation cannot detect that; only verification can.

2. Validation Checks

The syllabus requires six validation checks. Learn what each one rejects, and one example of each.

CheckWhat it testsExample
Range check The value falls between a stated lower and upper limit A month must be from 1 to 12; 13 is rejected
Length check The data has an exact number, or an acceptable number, of characters A password must be at least 8 characters
Type check The data is of the required data type Age must be an integer; "twelve" is rejected
Presence check Data has actually been entered and the field is not empty An email address cannot be left blank
Format check The data follows a required pattern of characters A date entered as dd/mm/yyyy
Check digit An extra digit calculated from the others, recalculated to confirm the number was entered correctly The final digit of a barcode or ISBN

A range check in pseudocode

REPEAT OUTPUT "Enter a month (1 to 12): " INPUT Month IF Month < 1 OR Month > 12 THEN OUTPUT "Invalid - must be between 1 and 12" ENDIF UNTIL Month >= 1 AND Month <= 12
A validation check must do two things: reject the invalid data and ask again. A check that prints an error message but then carries on with the bad value has not validated anything.

Length check versus format check

These are easy to mix up. A length check counts characters. A format check inspects the arrangement of characters.

Data enteredLength check (must be 7)Format check (2 letters then 5 digits)
AB12345PassesPasses
1234567PassesFails — no letters
AB123Fails — only 5Fails

How a check digit works

A check digit is calculated from the other digits and stored as part of the number. When the number is entered, the program repeats the calculation and compares the result with the digit supplied. If they differ, a digit was mistyped or transposed.

  • It detects a single mistyped digit
  • It detects two digits swapped round (transposition), e.g. 45 typed as 54
  • It detects missing or extra digits

3. Verification Checks

The syllabus requires two verification methods.

MethodHow it worksTypical use
Visual check The person entering the data reads it back on screen and compares it with the original source document Checking a typed address against a paper form
Double entry check The data is entered twice and the computer compares the two versions. If they differ, at least one is wrong Confirming a new password or email address
A visual check is not the computer checking the data. It is a human comparing what is on screen with the original. Describing it as the program "looking at" the data does not earn the mark.
Why double entry is not foolproof: if the user makes the same mistake twice, the two entries match and the error passes. This is a valid evaluation point in extended-answer questions.

4. Validation and Verification Together

Real systems use both, because they catch different problems.

ValidationVerification
Question askedIs the data reasonable?Was the data entered accurately?
Performed byThe program, automaticallyThe user, or the program comparing two entries
CatchesImpossible or badly formed valuesTyping and copying mistakes
MissesWrong but plausible valuesValues that are accurately copied but nonsensical

5. Exam Focus

Name the check, do not just describe it. Questions ask you to identify a suitable validation check. "Make sure the number isn't too big" scores nothing; "range check" scores the mark.
Give the limits when asked for a range check. State the actual boundaries relevant to the scenario, e.g. "a range check to ensure the mark is between 0 and 100", not simply "a range check".
Do not offer a type check where a range check is needed. A common error is answering "type check" for a value that is the right type but out of range. Check what the invalid data in the question actually is before choosing.
Validation is not verification. If a question asks for a verification method, only visual check and double entry check are acceptable. Listing range or length checks earns nothing.

Quick self-check

  • State the difference between validation and verification in one sentence each.
  • Name the six validation checks.
  • Give a value that passes a length check but fails a format check.
  • Explain one situation a double entry check fails to detect.
  • A field must contain a percentage. Name two suitable validation checks and state what each rejects.