Validation and Verification
Data validation and data verification both improve data quality, but they answer different questions.
You can read this note directly if you know basic Python functions, strings, and Boolean expressions.
Caption: Validation checks whether data satisfies rules; verification checks whether an entry matches its source or repeated entry.
The Core Distinction
- Validation: Is the data acceptable according to predefined rules?
- Verification: Was the data entered or transferred accurately?
A value can pass validation and still be wrong.
Example:
| Intended mark | Entered mark | Range validation | Verification |
|---|---|---|---|
72 | 72 | passes | matches |
72 | 27 | passes | does not match |
Both 72 and 27 are valid marks, but only one is the intended value.
Validation
Validation checks whether input satisfies rules such as permitted range, pattern, length, or presence.
For a mark that must be an integer from 0 to 100:
| Input | Result | Reason |
|---|---|---|
72 | valid | within range |
101 | invalid | above range |
"abc" | invalid | not an integer |
Validation reduces unsuitable input. It does not guarantee factual accuracy.
Verification
Verification checks whether data has been copied or entered correctly.
Common methods include:
- double entry: enter the data twice and compare the two entries;
- proofreading or visual checking: compare the entered data with the original source.
Example:
| Original phone number | Entered value | Format validation | Verification |
|---|---|---|---|
91234567 | 91234567 | valid | matches |
91234567 | 91234568 | valid | does not match |
Verification also cannot prove that the original source itself is factually correct. It checks agreement with that source or intended entry.
Validation Checks
Caption: Choose the validation check that matches the rule: range, format, length, presence, or check digit.
Presence Check
A presence check ensures that a required field is not empty.
def has_presence(text):
return text.strip() != ""Examples:
assert has_presence("Aisha") is True
assert has_presence(" ") is False
assert has_presence("") is FalseA presence check does not check whether the content is meaningful.
Range Check
A range check ensures that a numeric value lies within specified limits.
def valid_mark(mark):
return 0 <= mark <= 100Examples:
assert valid_mark(0) is True
assert valid_mark(100) is True
assert valid_mark(101) is FalseState whether the endpoints are included. Here, both 0 and 100 are valid.
Length Check
A length check ensures that data has an allowed number of characters.
def has_eight_characters(text):
return len(text) == 8A length check alone does not ensure that all characters are digits.
Format Check
A format check ensures that data follows a required pattern.
def valid_sg_phone_format(text):
return len(text) == 8 and text.isdigit()This combines a length check with a simple format requirement.
For a date format such as dd/mm/yyyy, a beginner-readable check can inspect separators and component lengths:
def has_date_format(text):
parts = text.split("/")
if len(parts) != 3:
return False
day, month, year = parts
return (
len(day) == 2
and len(month) == 2
and len(year) == 4
and day.isdigit()
and month.isdigit()
and year.isdigit()
)This checks the shape of the input, not whether it represents a real calendar date. For example, "31/02/2026" has the required format but is not a valid calendar date.
Check Digit
A check digit is calculated from the other digits or characters in a code and stored with it. When the code is entered, the system recalculates the check digit and compares the result with the supplied one.
Caption: The code is accepted only when the recalculated check digit matches the supplied check digit.
Simple teaching example:
def calculate_check_digit(digits):
total = 0
for digit in digits:
total = total + int(digit)
return str(total % 10)
def has_valid_check_digit(code):
data = code[:-1]
supplied = code[-1]
expected = calculate_check_digit(data)
return supplied == expectedTrace for code = "123455":
| Step | Value |
|---|---|
| data digits | "12345" |
| sum | 1 + 2 + 3 + 4 + 5 = 15 |
| calculated check digit | "5" |
| supplied check digit | "5" |
| result | accepted |
This is an original teaching algorithm, not an ISBN, banking, or identity-card algorithm. Real systems use different weighted calculations.
A check digit can detect many common transcription errors, but no check-digit scheme catches every possible error.
Combining Checks
Real validation often uses more than one check.
Example rule:
A phone number must be present, contain exactly 8 characters, and contain digits only.def valid_phone(text):
return (
text.strip() != ""
and len(text) == 8
and text.isdigit()
)The checks should be applied before the data is stored or processed.
Paper 1 and Paper 2 Emphasis
For written questions, be ready to:
- distinguish validation from verification;
- name and explain an appropriate validation check;
- explain why validation does not guarantee correctness.
For practical work, be ready to:
- implement short validation functions;
- display a useful error message;
- request re-entry until valid input is supplied;
- test normal, abnormal, and extreme cases.
Common Mistakes
- Saying validation guarantees that data is correct.
- Saying verification checks whether data is sensible.
- Confusing a presence check with a format check.
- Treating
len(text) == 8as sufficient for an 8-digit number. - Assuming a correctly formatted date must be a real date.
- Assuming a check digit catches every possible error.
Check Your Understanding
- Why can a valid email address still be wrong?
- Which check rejects an empty required field?
- Which check rejects a mark of
-1when the valid range begins at 0? - What is compared when a check digit is verified?
Answers:
- It may satisfy the format rule but differ from the intended address.
- Presence check.
- Range check.
- The supplied check digit is compared with the recalculated check digit.