Docs

Topic 7 · Algorithm design and problem-solving

Validation and verification

Range, length, type, presence, format, and check digit checks, plus double entry and visual checks.

Lesson 4 of 5Syllabus 7.5updated October 31, 2026

Validation

Validation is an automatic check by the program that data is reasonable and meets set rules before it is accepted. It cannot tell whether the data is correct: an age of 15 passes a range check even if you are 16.

CheckMakes sure that...Example
RangeA value is between a lower and upper limitA percentage is 0 to 100
LengthData has an exact number, or a minimum/maximum number, of charactersA password is at least 8 characters
TypeData is the right data typeAn age is a whole number, not text
PresenceData has been entered and is not left blankAn email field is not empty
FormatData follows a patternA date is DD/MM/YYYY; a code is two letters then four digits
Check digitA code's final digit matches the one calculated from the othersISBNs and barcodes

A validation loop

A REPEAT ... UNTIL loop keeps asking until the input passes. This one does a range check and shows an error message each time the value is rejected.

Pseudocode
DECLARE Mark : INTEGER
REPEAT
    OUTPUT "Enter a mark from 0 to 100"
    INPUT Mark
    IF Mark < 0 OR Mark > 100
      THEN
        OUTPUT "Invalid mark, try again"
    ENDIF
UNTIL Mark >= 0 AND Mark <= 100
OUTPUT "Accepted: ", Mark

A length check

LENGTH() returns the number of characters in a string, so it is used for length checks.

Pseudocode
DECLARE Password : STRING
INPUT Password
WHILE LENGTH(Password) < 8 DO
    OUTPUT "Password must be at least 8 characters"
    INPUT Password
ENDWHILE

Verification

Verification checks that data has been copied or entered accurately, matching the original.

  • Double entry: the data is entered twice and the two entries are compared, as when you type a new password twice.
  • Visual check: the user reads the data on screen and compares it with the original document.

Key idea. Validation: is the data sensible? Verification: is the data the same as the original?

Key terms

Validation
An automated check that data is reasonable before it is accepted.
Verification
A check that data has been accurately copied or entered.
Range check
Checks a value lies between set limits.
Double entry
Entering data twice and comparing the two entries.

Check yourself

Which validation check ensures a field is not left blank?Show answer

A presence check.

Why can data pass validation and still be wrong?Show answer

Validation only checks data is sensible and follows the rules, not that it is the true value.

Suggest a validation check for a UK postcode such as CB2 1TN.Show answer

A format check (letters and digits in the right pattern), or a length check.