Learning Objectives
By the end of this lesson, you will be able to:
- Understandthe need for validation checks to be made on input data
- Describethe six types of validation check: range, length, type, presence, format and check digit
- WriteCIE pseudocode and Python code to perform each type of validation check
- Understandthe need for verification checks to be made on input data
- Describethe different types of verification check: double entry, visual/screen check, parity check and checksum
- Explainthe difference between validation and verification
- Applyvalidation and verification techniques to real-world scenarios
Key Terms
Validation
An automated process where a computer checks if a user input is sensible and meets the program's requirements before it is processed.
Verification
The act of checking that data is accurate when entered into a system — that data does not change, either accidentally or on purpose, as it is entered.
Range check
Ensures that the data entered as a number falls within a particular range (e.g. a percentage between 0 and 100 inclusive).
Length check
Checks the length of a string — ensures the input includes the correct/minimum/maximum number of characters.
Type check
Checks the data type of a field — ensures the input is of the correct data type (e.g. integer, real, string).
Presence check
Looks to see if any data has been entered in a field — ensures all required data has been entered and rejects blank inputs.
Format check
Ensures that data has been entered in the correct format — done using pattern matching and string handling (e.g. DD/MM/YYYY or an email address).
Check digit
A numerical value that is the final digit of a larger code, such as a barcode or ISBN. It is calculated by applying an algorithm to the code.
Double entry checking
A verification method where important data has to be entered twice in separate input boxes, then compared to ensure they both match.
Visual (screen) check
A manual verification check where the user visually checks the data on the screen and confirms it is correct before proceeding.
Parity check
A verification method used during data transmission that checks whether the number of set bits is odd or even.
Checksum
A verification method used during data transmission where a calculated value is compared to a transmitted value to detect errors.
1. Validation vs Verification
Bothvalidationandverificationare used to ensure that data entered into a computer system is correct and reasonable. The use of both is vital for the smooth running of computer systems.
Validation
Validationis performedautomatically by the computer systemto ensure that only reasonable data is accepted. It checks that data input by the usermeets specific criteria/rulesbefore processing.
Verification
Verificationis used to check that the datadoes not changeas it is being entered. It ensures that data isaccurateand is what was intended to be entered.
| Validation | Verification |
|---|---|
| range check | double entry (data entry) |
| length check | screen/visual check (data entry) |
| type check | parity check (data transmission) |
| character check | checksum (data transmission) |
| format check | |
| presence check | |
| check digits |
Key difference
- Validationensures that onlyreasonable datais accepted. It is done automatically by the computer.
- Verificationensures that data isnot changed, either accidentally or on purpose, as it is entered. It often involves the user.
- Both cover a variety of techniques that attempt to minimise the number of errors caused by inaccurate data.
Why validation is important
Without validation, "bad data" can enter a system and cause serious problems. For example, a user could enter:
- A date of birth of20/13/1878(invalid month and unrealistic age)
- A name containing numbers likeBa1
- A city namedSandton Doll(misspelled or made up)
Validation rules help prevent such errors from being accepted.
Activity 1: Validation or Verification?
Classify each of the following as either a validation check or a verification check, and explain your reasoning.
- Checking that a date of birth is entered in the format DD/MM/YYYY.
- Asking the user to type their new password twice and comparing both entries.
- Checking that an age entered is between 0 and 110.
- Displaying all the data entered on a summary screen and asking the user to click "Submit" to confirm.
- Checking that a telephone number contains only digits.
- Checking that a barcode's final digit matches the value calculated from the other digits.
Solution:
- Validation(format check) — the computer automatically checks that the data follows a specific pattern.
- Verification(double entry) — the two entries are compared to ensure the data did not change during entry.
- Validation(range check) — the computer automatically checks the value falls within a reasonable range.
- Verification(visual/screen check) — the user manually checks the data and confirms it is correct.
- Validation(type/format check) — the computer automatically checks the data type of the input.
- Validation(check digit) — the computer calculates and compares a check digit to verify the integrity of the code.
Check Your Understanding: Validation vs Verification
1. Define "validation" and "verification". [4 marks]
Answer
- [2 marks]Validation— an automated process where a computer checks if a user input is sensible and meets the program's requirements before it is processed
- [2 marks]Verification— the act of checking that data is accurate when entered into a system; ensures data does not change, either accidentally or on purpose, as it is entered
2. Explain the main difference between validation and verification. [2 marks]
Answer
- [1 mark]Validation checks that data is reasonable and sensible (done automatically by the computer)
- [1 mark]Verification checks that data is accurate and has not changed during entry (often involves the user)
3. Name the six types of validation check. [6 marks]
Answer
- [1 mark]Range check
- [1 mark]Length check
- [1 mark]Type check
- [1 mark]Presence check
- [1 mark]Format check
- [1 mark]Check digit
4. Name three types of verification check. [3 marks]
Answer
- [1 mark]Double entry checking (data entry)
- [1 mark]Screen/visual check (data entry)
- [1 mark]Parity check (data transmission) or checksum (data transmission)
5. Why is validation important? Give an example of data that could be prevented from entering a system. [3 marks]
Answer
- [1 mark]Validation prevents "bad data" from entering a system, which could cause errors later
- [1 mark]It makes programs more robust and user-friendly
- [1 mark]Example: an age of 250 years old would be rejected by a range check (e.g. between 0 and 110)
6. Explain why a password field might use more than one type of validation check. [2 marks]
Answer
- [1 mark]A password field could have alength check(e.g. at least 8 characters), apresence check(must not be blank) and atype check(must contain both letters and numbers)
- [1 mark]Using more than one check makes the password more secure and helps prevent weak passwords
2. Types of Validation Check (7.5a)
Validation checks are essential in computer programming to ensure that input data is accurate, reliable, and within the expected parameters. There aresix typesof validation check.
Range Check
Ensures the data entered as a number falls within a particular range.
Example:percentage marks between 0 and 100 inclusive; age between 10 and 18.
Length Check
Checks the length of a string — ensures the input includes the correct/minimum/maximum number of characters.
Example:a 4-digit PIN; a password of 8 or more characters; a car licence plate.
Type Check
Checks the data type of a field — ensures the input is of the correct data type.
Example:an age should be entered as an integer (whole number); a name should be a string.
Presence Check
Looks to see if any data has been entered in a field — ensures all required data has been entered.
Example:an email address must be given for an online transaction; reject blank inputs.
Format Check
Ensures that data entered matches a desired pattern, using pattern matching and string handling.
Example:a date in the form DD/MM/YYYY; an email address following "XXXXX@XXXXX.XXX"; a CUB number in the form CUB9999.
Check Digit
A numerical value that is the final digit of a larger code, calculated by applying an algorithm to the code.
Example:barcodes, ISBN numbers, Vehicle Identification Numbers (VIN).
More than one check
There can be occasions where more than one type of validation will be used on a field. An example of this could be a password field which could have alength,presenceandtypecheck on it.
Interactive: Try Validation Checks
Type values into the fields below to see how different validation checks work. Invalid data will be rejected with an error message.
How it works:Each field applies a different validation check. When the input passes the check, a green success message appears. When it fails, a red error message explains what is wrong.
2.1 Range Check
Arange checkensures that the input data falls within a specified range. For example, if a program asks for a person's age, you might limit entries to be between 13 and 100. This would prevent people under the age of 13 from signing up and also prevent unrealistic ages such as 250 years old.
CIE Pseudocode
Python Code
Real-Life Example
A student registration system requires students to register for a school event. The system uses a range check to ensure the student's age is within an acceptable range (e.g. 10 to 18 years old). If a student enters 7 or 25, the system rejects the entry.
2.2 Length Check
Alength checkensures that the length of the input data is within a specific range. For example, a password might need to be at least 8 characters long, or a PIN must be exactly 4 digits.
CIE Pseudocode
Python Code
Real-Life Example
When you create a new password on most websites, a length check ensures it is at least 8 characters long. When you enter a bank PIN at an ATM, a length check ensures it is exactly 4 digits.
2.3 Type Check
Atype checkensures that the input data is of the correct data type. For example, an age should be entered as an integer (whole number), not as text or a decimal.
CIE Pseudocode
Python Code
2.4 Presence Check
Apresence checkensures that some data has been entered and the value has not been left blank. For example, an email address must be given for an online transaction, and a user cannot sign up to a service if they have left the email field empty.
CIE Pseudocode
Python Code
2.5 Format Check
Aformat checkensures that data entered matches a desired pattern. For example, if a user is required to enter an email address, it should follow a set pattern of "XXXXX" + @ + "XXXXX" + "." + "XXX". This would allow an email address such as "example@gmail.com" to be accepted. Another example is a CUB number that must be in the form CUB9999, or a gender entry that must be M or F.
CIE Pseudocode (email format)
Python Code (email format)
2.6 Check Digit
Acheck digitis the last digit included in a code or other identification number. It is calculated from all the other digits in the code. Check digits are commonly used with:
- Barcodes
- ISBN numbers
- Vehicle Identification Numbers (VIN)
Check Digit Calculation Example
Let's say the ID without the check digit is12345. To calculate the check digit:
- Sum of digits: 1 + 2 + 3 + 4 + 5 = 15
- Multiply by 7: 15 × 7 = 105
- Take modulus 10: 105 % 10 = 5
- So the complete ID with the check digit would be123455
Check Digit Validation Example
To validate the ID123455:
- Remove the last digit (check digit): 12345
- Sum of digits: 1 + 2 + 3 + 4 + 5 = 15
- Multiply by 7: 15 × 7 = 105
- Calculated check digit: 105 % 10 = 5
- Since the calculated check digit (5) matches the provided check digit (5), the ID is considered valid.
Activity 2: Choose the Right Validation Check
For each scenario below, state which validation check would be most appropriate and explain why.
- A website asks a user to enter their date of birth in the form DD/MM/YYYY.
- A school exam system asks for a percentage mark.
- A user creates a password that must be at least 8 characters long.
- An online form requires the user to enter their email address.
- A product barcode is scanned at a supermarket till.
- A form asks for the user's age as a whole number of years.
Solution:
- Format check— ensures the date follows the DD/MM/YYYY pattern.
- Range check— ensures the mark is between 0 and 100 inclusive.
- Length check— ensures the password has at least 8 characters.
- Presence check(and possibly format check) — ensures the email field is not left blank and follows a valid email pattern.
- Check digit— the barcode's last digit is validated against a calculation from the other digits.
- Type check— ensures the age is entered as an integer (whole number), not as text or a decimal.
Check Your Understanding: Validation Checks
1. Describe what a range check does and give an example of where it would be used. [3 marks]
Answer
- [1 mark]A range check ensures that the data entered as a number falls within a particular range
- [1 mark]It compares the input value against a minimum and maximum allowed value
- [1 mark]Example: a percentage mark must be between 0 and 100 inclusive; an age must be between 10 and 18
2. Write CIE pseudocode for a presence check that ensures a username is not left blank. [4 marks]
Answer
Marking:OUTPUT prompt (1), REPEAT loop (1), IF check for empty string (1), UNTIL condition (1).
3. Explain what a check digit is and how it is used. [3 marks]
Answer
- [1 mark]A check digit is the final digit of a larger code or identification number
- [1 mark]It is calculated from all the other digits in the code using a specific formula
- [1 mark]It is used to verify the integrity of the code — if the calculated digit matches the provided digit, the code is valid. Used with barcodes, ISBN numbers and VINs.
4. A form asks for a person's email address. Describe how both a presence check and a format check could be applied to this field. [3 marks]
Answer
- [1 mark]Presence check:checks the email field is not left blank; if empty, the user is asked to enter it again
- [1 mark]Format check:checks the email follows a valid pattern, containing an @ symbol and a dot after it, e.g. "XXXXX@XXXXX.XXX"
- [1 mark]Both checks together ensure that the email is provided and is in a valid format before it is accepted
5. A student ID is 123456. Using the check digit method shown (sum digits × 7, modulus 10), verify whether this ID is valid. [3 marks]
Answer
- [1 mark]Remove the check digit: 12345
- [1 mark]Sum digits: 1+2+3+4+5 = 15; Multiply by 7: 15 × 7 = 105; Modulus 10: 105 % 10 = 5
- [1 mark]The calculated check digit (5) does not match the provided check digit (6), so the ID123456isnot valid.
6. Give two benefits of using input validation techniques in a program. [2 marks]
Answer
- [1 mark]Makes the program more robust and user-friendly
- [1 mark]Prevents further errors occurring later in the algorithm
3. Types of Verification Check (7.5b)
Verificationensures that data is not changed, either accidentally or on purpose, as it is being entered. There are several types of verification check used during data entry and data transmission.
Double Entry Checking
Important data has to be entered twice, sometimes by different people. The system then compares both entries to check they are the same before accepting the data.
Example:entering a new password twice when creating an account; entering an email address twice for a bank transaction.
Visual (Screen) Check
A manual check performed by the user who is entering the data. All the data is displayed back to the user, usually with a tick-box or button asking them to verify the data before submission.
Example:a summary page before confirming an online order; a "Please verify the data you have entered is correct before clicking submit" screen.
Parity Check
A verification method used during data transmission that checks whether the number of set bits is odd or even. A parity bit is added to make the total number of 1s either odd or even.
Example:when data is sent over a network, a parity bit helps detect if a bit has been flipped during transmission.
Checksum
A verification method used during data transmission where a calculated value (the checksum) is sent alongside the data. The receiver recalculates the checksum and compares it to the transmitted value.
Example:sending a file over the internet; if the checksums do not match, the file is corrupted and must be re-sent.
3.1 Double Entry Checking
Double entry verification is a process whereby important data has to be entered twice, sometimes by different people. The system then compares both entries to check they are the same before accepting the data.
CIE Pseudocode
Python Code
3.2 Visual (Screen) Check
A screen check or visual check is simply a manual check performed by the user who is entering the data. Once data entry is complete, all the data is displayed back to the user, usually with a tick-box or button asking them to verify the data before submission.
CIE Pseudocode
Python Code
3.3 Parity Check and Checksum
Parity checksandchecksumsare verification methods used duringdata transmission. They help detect errors that occur when data is sent from one place to another.
| Method | How it works | Use case |
|---|---|---|
| Parity check | A parity bit is added to each byte so that the total number of 1s is either always odd or always even. The receiver checks the parity and flags an error if it doesn't match. | Data transmitted over a network; simple error detection |
| Checksum | A calculated value (the checksum) is sent with the data. The receiver recalculates the checksum from the received data and compares it to the transmitted value. | Sending files over the internet; verifying file integrity |
Purpose of verification checks
The purpose of these verification checks is to enhance the quality and reliability of input data, reducing the likelihood of errors, inaccuracies, and inconsistencies. Visual checks catch obvious mistakes, while double entry checks provide an additional layer of validation by comparing independent entries, ensuring data integrity and reliability in critical applications.
Activity 3: Verification in Action
A user is creating an account on a website. Describe how each of the following verification methods could be used:
- Double entry checking
- Visual check
Explain why verification is important when creating a new account.
Solution:
- Double entry checking:The user is asked to enter their new password twice (in two separate boxes). The system compares both entries to ensure they match. If they don't, an error message is shown asking the user to try again.
- Visual check:After filling in all details, the user is shown a summary screen displaying all the data they entered. They must review it and click "Submit" to confirm everything is correct, or click "Edit" to go back and fix mistakes.
Why verification is important:Mistakes such as entering a password incorrectly mean being locked out of the account immediately. Verification ensures the user can access their account later, and that important details (like email or address) are correct.
Check Your Understanding: Verification Checks
1. Describe how double entry verification works. [3 marks]
Answer
- [1 mark]Important data has to be entered twice
- [1 mark]Sometimes by different people
- [1 mark]The system then compares both entries to check they are the same before accepting the data; if they do not match, an error message is shown
2. What is a visual check and when would it be used? [3 marks]
Answer
- [1 mark]A visual check is a manual check performed by the user who is entering the data
- [1 mark]All the data is displayed back to the user, usually with a tick-box or button asking them to verify before submission
- [1 mark]It is used at the end of data entry, for example on a summary/confirmation page before an online order is placed
3. Explain why a parity check is used during data transmission. [3 marks]
Answer
- [1 mark]When data is transmitted, bits can be flipped or lost due to interference
- [1 mark]A parity bit is added to make the total number of 1s either always odd or always even
- [1 mark]The receiver checks the parity and can detect if an error has occurred during transmission
4. Explain the purpose of validation and verification checks during data entry. Include an example of each. [4 marks]
Answer
Validation check:
- [1 mark]Description: to test if the data entered is possible / reasonable / sensible
- [1 mark]Example: a range check tests that data entered fits within specified values (e.g. age between 0 and 110)
Verification check:
- [1 mark]Description: to test if the data input is the same as the data that was intended to be input
- [1 mark]Example: a double entry check expects each item of data to be entered twice and compares both entries to check they are the same
5. Write CIE pseudocode for a double entry verification check when a user creates a new password. [4 marks]
Answer
Marking:REPEAT loop (1), input both passwords (1), IF comparison (1), error message and UNTIL condition (1).
6. Why might a bank use both validation and verification checks for an online transaction? [3 marks]
Answer
- [1 mark]Validation ensures the data entered is sensible — for example, the account number is the correct length and contains only digits
- [1 mark]Verification ensures the data has not changed during entry — for example, double entry of the account number to catch typing mistakes
- [1 mark]Together they reduce the risk of errors, fraud and failed transactions, which is critical in banking
4. Worked Examples & Past Paper Practice
Worked Example: Validation and Verification
Describe the purpose of validation and verification checks during data entry. Include an example for each. [4 marks]
Show Mark Scheme
Answer:
Validation check:
- [1 mark]Description: to test if the data entered is possible / reasonable / sensible
- [1 mark]Example: a range check tests that data entered fits within specified values (e.g. 0-100); length/type/presence/format are also acceptable
Verification check:
- [1 mark]Description: to test if the data input is the same as the data that was intended to be input
- [1 mark]Example: a double entry check expects each item of data to be entered twice and compares both entries to check they are the same; visual check is also acceptable
Past Paper Question: Validation Methods
A school uses a computer system to record student information. The system asks for the following data:
- Student name
- Date of birth (DD/MM/YYYY)
- Age (between 10 and 18)
- Email address
- Student ID (5 digits)
For each field, state one type of validation check that should be applied and explain why it is appropriate.
Show Mark Scheme
Answer:
| Field | Validation check | Why appropriate |
|---|---|---|
| Student name | Presence check | Ensures the student's name is not left blank — every student must have a name recorded. |
| Date of birth | Format check | Ensures the date follows the DD/MM/YYYY pattern, preventing ambiguous or incorrectly formatted dates. |
| Age | Range check | Ensures the age is between 10 and 18 — the acceptable range for the school's students. |
| Email address | Format check | Ensures the email follows a valid pattern (contains @ and a dot after it), so it can be used for communication. |
| Student ID | Length check (and/or check digit) | Ensures the ID is exactly 5 digits; a check digit could verify the ID's integrity. |
Key Takeaways
- Validationis an automated process where the computer checks that data is sensible and meets the program's requirements before processing.
- Verificationchecks that data is accurate and has not changed, either accidentally or on purpose, as it is entered.
- The six types ofvalidation checkare: range, length, type, presence, format and check digit.
- Arange checkensures a numeric value falls within a specified range (e.g. 0–100 for a percentage).
- Alength checkensures input has the correct/minimum/maximum number of characters (e.g. a 4-digit PIN).
- Atype checkensures input is of the correct data type (e.g. an age must be an integer).
- Apresence checkensures a field is not left blank (e.g. an email address must be entered).
- Aformat checkensures input matches a desired pattern (e.g. DD/MM/YYYY or an email address).
- Acheck digitis calculated from a code and used to verify the code's integrity (e.g. barcodes, ISBN).
- The mainverification methodsare double entry checking, visual/screen check, parity check and checksum.
- Double entryrequires important data to be entered twice and compared for consistency.
- Avisual checkdisplays data back to the user for confirmation before submission.
- Parity checksandchecksumsare used during data transmission to detect errors.
- Together, validation and verification make programs more robust, user-friendly and reliable, minimising errors caused by inaccurate data.
Question Bank
1. Define validation and verification and explain the key difference between them. [5 marks]
Answer
- [2 marks]Validation— an automated process where a computer checks if a user input is sensible and meets the program's requirements
- [2 marks]Verification— checking that data is accurate when entered and does not change as it is entered
- [1 mark]Key difference: validation ensures data isreasonable; verification ensures data isaccurateand unchanged
2. Name the six types of validation check and give a brief description of each. [12 marks]
Answer
- [2 marks]Range check— ensures data entered as a number falls within a particular range (e.g. 0–100)
- [2 marks]Length check— ensures the input has the correct/minimum/maximum number of characters (e.g. 4-digit PIN)
- [2 marks]Type check— ensures the input is of the correct data type (e.g. integer)
- [2 marks]Presence check— ensures a field has not been left blank
- [2 marks]Format check— ensures data matches a desired pattern (e.g. DD/MM/YYYY)
- [2 marks]Check digit— a final digit calculated from the code to verify its integrity (e.g. barcode, ISBN)
3. Write CIE pseudocode for a range check that ensures a percentage mark is between 0 and 100 inclusive. [4 marks]
Answer
Marking:OUTPUT prompt (1), REPEAT loop (1), IF check with correct conditions (1), UNTIL condition (1).
4. Explain how a check digit is calculated and used, using the ID 12345 as an example. [4 marks]
Answer
- [1 mark]A check digit is the final digit of a larger code, calculated from all the other digits
- [1 mark]Example calculation: sum of digits (1+2+3+4+5 = 15), multiply by 7 (15 × 7 = 105), modulus 10 (105 % 10 = 5)
- [1 mark]So the complete ID with the check digit would be 123455
- [1 mark]To validate: the same calculation is performed on the first digits and compared to the check digit. If they match, the code is valid.
5. Describe two types of verification check used during data entry and explain why each is useful. [4 marks]
Answer
- [2 marks]Double entry checking— important data is entered twice and the system compares both entries to ensure they match. Useful for passwords and bank details where mistakes are costly.
- [2 marks]Visual/screen check— all data is displayed back to the user who confirms it is correct before submission. Useful for catching obvious mistakes before data is saved.
6. Write CIE pseudocode for a length check that ensures a PIN is exactly 4 digits. [4 marks]
Answer
Marking:OUTPUT prompt (1), REPEAT loop (1), LENGTH check (1), UNTIL condition (1).
7. A company uses a parity check when transmitting data. Explain what this means and how it helps detect errors. [4 marks]
Answer
- [1 mark]A parity bit is added to each byte/character to make the total number of 1s either always odd (odd parity) or always even (even parity)
- [1 mark]The receiver counts the 1s in the received data and checks whether the parity matches
- [1 mark]If the parity does not match, an error has occurred during transmission
- [1 mark]This method can detect single-bit errors (but not all multi-bit errors)
8. A program asks a user for their age. Write CIE pseudocode that validates the age with a type check (must be a whole number) AND a range check (must be between 10 and 18). [6 marks]
Answer
Marking:OUTPUT prompt (1), REPEAT loop (1), type check using DIV (1), range check (1), error messages (1), UNTIL condition combining both (1).