7.5 Validation and Verification

Question Bank · 9 Questions

Objectives: Students should be able to —

  • 1 Describe what is meant by validation and verification.
  • 2 State when it is appropriate to use validation.
  • 3 State when it is appropriate to use verification.
  • 4 Describe with examples the types of validation — Range, Length, Type, Presence, Format and Check digit.
  • 5 Write pseudocode algorithms to perform range, length, type and presence checks.
  • 6 Choose appropriate validation and verification checks for real-world input fields.

Validation and Verification — Definitions and Differences

(a) Describe what is meant by validation and verification:

Validation:

  • Validation is an automatic check performed by a program to ensure that the data entered is sensible and reasonable before it is accepted by the system.
  • It does not check the accuracy of data.
  • It generates an error message when the input data is not valid, and gives an opportunity to re-enter the data.

Example: Presence check, type check, range check, format check, etc.

Verification:

  • Verification is a process performed to ensure that the data entered into a computer or transferred from one system to another exactly matches with the original data.
  • On data entry, verification is done either manually by visual check called Proof-reading, or automatically by software called Double-entry method, where the same data is entered twice and the two copies are compared with each other.
  • During data transmission, verification is done automatically by software using different error detection methods.

Example: Proof-reading, Double-entry method, Parity check, Checksum, Echo check, etc.

(b) Tick (✔) one box in each row to identify if the statement is about validation, verification or both:

Statement Validation Verification Both
Entering the data twice to check if both entries are the same.
Automatically checking that only numeric data has been entered.
Checking data entered into a computer system before it is stored or processed.
Visually checking that no errors have been introduced during data entry.

(c) Give difference between data Validation and Verification:

Data Validation Data Verification
Validation is an automatic computer check, done while entering data into the computer against the set validation rules. Verification is done either manually by Proof-reading or by entering the same data twice and comparing the two copies by computer, using software.
It ensures that the data entered is sensible and reasonable, but does not check its accuracy. It ensures that the data entered exactly matches the original source.
Validation is done before data is accepted and stored in computer. Verification is done after data is entered into the computer.

When to Use Validation and Verification

(a) (i) State when it is appropriate to use validation:

It is used when we need to ensure that the data entered is sensible, reasonable and consistent; accepted only if it falls within the set rules. It does not check the accuracy of data.

(a) (ii) State when it is appropriate to use verification:

It is used when we need to ensure that the data entered exactly matches the original source. It is done by either proof-reading or double-entry method.

(b) (i) Examples of validation checks:

  1. Range check — to ensure that a number falls within the specified range of values.
  2. Length check — to ensure that the data isn't too short or too long.
  3. Type check — to ensure the correct type of data like text, number or date.
  4. Presence check — to ensure that the data has been entered into a field.
  5. Format check — to ensure that the data is in the right format.
  6. Check digit — the last one digit in a code (number) is used to check that the other digits are correct.

(b) (ii) Examples of verification checks:

  1. Proof-reading / screen or visual check — checking the data entered against the original source visually by someone.
  2. Double entry — entering data twice and comparing the two copies using software.

Types of Validation Checks (with Examples)

Validation type How it works Example of its usage
Presence check Checks that the data has been entered into a field. In most databases a key field cannot be left blank (i.e. field cannot be left blank).
Type check Checks that the data entered is of an expected type, e.g. text, a number, date, etc. Name (Text), Date of birth (Date), Age (Number), Sex (Boolean), Price (Currency).
Format check Checks that the data is in the right format. A Passport number in the form L9999999, where L is any letter and 9 is any number.
Example: M5228907
Date Format check Checks that the data is in the right 'Date' format. Like dd/mm/yyyy or dd.mmm.yyyy
Example: 24/03/1968 or 24.Mar.1968
Length check Checks that the data isn't too short or too long. A password which needs to be minimum six letters long.
List check (or Look-up table) Checks that the data is in the List or Table. List of subjects of a particular grade.
Range check Checks that a value falls within the specified range. Student's marks must be — "Between 0 and 100".
Check digit The last one digit in a code (number) is used to check that the other digits are correct. Bar code readers in supermarkets use check digits to check the number read is correct and matches with the check digit.
Consistency (or Cross-field check) Checks that different fields in the same record correspond correctly. If 'Mr' has been entered into the title field, 'Male' must be entered into the gender field.
Spell check Looks up words in a dictionary. Checking the spelling for a word while typing.

Applying Validation and Verification to Real Inputs

(a) Why verification was chosen and how the programmer would verify this data:

  • To ensure the accuracy of input data — to make sure that they entered the data what they intended, without mistake.
  • The programmer could ask the contributor to type in each detail twice and then check that both values are equal.
  • If they are not equal then the input should be rejected.

(b) Validation checks that could be used for:

Email address

  • Format check — to check for @ symbol that separates the mail address and domain name; no space is allowed (white or blank).
  • Uniqueness check — to check and ensure that it should not match with another's email address.
  • Length check — to check and ensure that it should not contain more than 254 characters.

Password

  • Length check — to check if its length is minimum 8 characters.
  • Format check — to check if it contains a mixture of lower and upper-case letters, at least one digit (0 to 9) and one special character or symbol.
  • Presence check — to ensure that the field should not be left empty.

Telephone number

  • Length or Range checkvalidation to check if the number contains 7-digits; must be between 1000000 and 9999999.
  • Check digitverification to ensure the accuracy of input data; the last one digit of the number is used to check that the other digits are correct.

Pupil's name

  • Length checkvalidation to check if the length of name is less than or equal to 30 characters.
  • Visual checkverification to ensure the accuracy of input data; ask the user to check the name displayed on screen and confirm that it is correct.

ID-Card number (form XXX999)

  • Format checkvalidation to check if the input data is in the appropriate format with 3 characters and 3 digits.
  • Double-entryverification to ensure the accuracy of input data; ask the user to type in the number twice and then check that both the values are equal.

Pseudocode Algorithms for Validation Checks

Algorithm (Range check):

REPEAT INPUT "Enter the student's mark - ", StudentMark IF (StudentMark < 0 OR StudentMark > 100) THEN OUTPUT "The student's mark should be in the range 0 to 100, please re-enter the mark" ENDIF UNTIL (StudentMark >= 0 AND StudentMark <= 100)
Note: The REPEAT … UNTIL loop keeps prompting the user until a mark within the valid range (0–100 inclusive) is entered. The condition inside IF uses OR to detect out-of-range values, while the loop exit condition uses AND to ensure both bounds are satisfied.

Algorithm (Length check):

REPEAT INPUT "Enter the password between 8 and 12 characters in length - ", Password IF (LENGTH(Password) < 8 OR LENGTH(Password) > 12) THEN OUTPUT "Invalid, your password should be between 8 and 12 characters in length. Please re-enter the password." ENDIF UNTIL (LENGTH(Password) >= 8 AND LENGTH(Password) <= 12)
Note: The built-in LENGTH() function returns the number of characters in the string. The loop only terminates when the password length satisfies both bounds (8 ≤ length ≤ 12).

Algorithm (Type check):

REPEAT INPUT "Enter the mark in whole number - ", Mark IF Mark <> DIV(Mark, 1) THEN OUTPUT "Invalid, mark must be in whole number. Please re-enter the mark." ENDIF UNTIL Mark = DIV(Mark, 1)
Note: DIV(Mark, 1) returns the integer part of Mark (whole-number division by 1). If Mark is a real number with a fractional part, then Mark ≠ DIV(Mark, 1) and the input is rejected. Only a true integer (whole number) passes the check.

Algorithm (Presence check):

REPEAT INPUT "Enter the student's ID - ", StdID IF StdID = "" THEN OUTPUT "Sorry, student's ID cannot be left blank. Please re-enter the student's ID." ENDIF UNTIL StdID <> ""
Note: An empty string "" represents a blank field. The loop keeps prompting the user until StdID is no longer empty — guaranteeing that some data has been entered.

Revision: Statements and Key Computing Terms

Statement Key Term
An automatic check performed by a program to ensure that the data entered is sensible and reasonable before it is accepted.Validation
A process performed to ensure that data entered into a computer exactly matches the original source.Verification
Checking the data entered against the original source visually by someone.Proof-reading (Visual check)
Entering data twice and comparing the two copies using software.Double-entry method
Checks that the data has been entered into a field (field cannot be left blank).Presence check
Checks that the data entered is of an expected type, e.g. text, number, date.Type check
Checks that the data is in the right format (e.g. L9999999 for a passport number).Format check
Checks that the data isn't too short or too long.Length check
Checks that a value falls within a specified range (e.g. marks between 0 and 100).Range check
The last digit in a code (number) used to check that the other digits are correct.Check digit
Checks that the data is in a list or look-up table of allowed values.List check (Look-up table)
Checks that different fields in the same record correspond correctly (e.g. Mr → Male).Consistency (Cross-field) check
Looks up words in a dictionary while typing.Spell check
Verification done automatically by software during data transmission to detect errors.Parity check / Checksum / Echo check