Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Computer Science

Teacher: Maruf Ahmed


Validation and verification discussion

A computer system should accept only the required values for a scenario and reject all other values that
do not meet the requirement for that scenario. Two different checking methods are used to accomplish
this task. One is validation and the other one is verification. Both the methods are used during data
entry.

Validation: is a method which checks if the data is meaningful / reasonable / sensible / within the range
or meets the criteria that have been set. It is always an automated checking by a program before it is
accepted by a computer system. This process continues until an input value is given to the requirement
set by the program. There may be different types of validation checks that could be applied on same piece
of data.

For ensuring validation, conditional loops (WHILE or REPEAT) are always used.

Types of validation check:


i. Range check (used for numbers / dates): To check that the value is within a defined range or
not. A range check will have both lower limit and upper limit covered.

Pseudocode example:
The following example will accept value within the range from 0 to 100 inclusive. If not then
program will not proceed further unless the acceptable value is given.

//Solution using REPEAT loop


REPEAT
OUTPUT "Please enter the student's mark: "
INPUT StudentMark
IF StudentMark < 0 OR StudentMark > 100
THEN
OUTPUT "The mark is outside the range, please re-enter the mark"
ENDIF
UNTIL StudentMark >= 0 AND StudentMark <= 100

//Solution using WHILE loop


OUTPUT "Please enter the student's mark: "
INPUT StudentMark
WHILE StudentMark < 0 OR StudentMark > 100 DO
OUTPUT "Mark should be in the range 0 to 100 inclusive, please re-enter the mark "
INPUT StudentMark
ENDWHILE

ii. Length check (used mainly for characters): It counts number of characters and checks if the
number of characters are of a fixed length or a reasonable length.

Pseudocode example of reasonable length


INPUT Name
WHILE LENGTH(Name) < 5 OR LENGTH(Name) > 50 DO
OUTPUT “Name must be between 5 and 50 characters inclusive”
INPUT Name
ENDWHILE

Page 1 of 6
// Pseudocode example of fixed length
INPUT Password
WHILE LENGTH(Password) < > 10 DO
OUTPUT “Password must be exactly 10 characters long”
INPUT Password
ENDWHILE

N.B. LENGTH() function which is used for STRING data type counts and returns number of
characters for a variable

iii. Type check: Checks whether the data is of any particular type or not. For example only whole
numbers, only letters etc. to be accepted by a system.
Pseudocode example:
The following algorithm will accept only whole numbers and will reject any decimal numbers

INPUT Number
WHILE Number < > Number DIV 1 DO
OUTPUT “Wrong input, the value must be an integer”
INPUT Number
ENDWHILE

REPEAT
INPUT Number
IF Number < > Number DIV 1
THEN
OUTPUT “Wrong input, the value must be an integer”
ENDIF
UNTIL Number = Number DIV 1
//DIV operator gives integer division

iv. Presence check: It checks if data is present in a field or not. To be present the length of the field
must be more than 0 characters in length.
Pseudocode example:

// “” (two speech marks together) means empty string and for an empty string the length is 0
OUTPUT “Please enter your name: ”
INPUT Name
WHILE Name = “” DO
OUTPUT “No data given. Data must be given for this field”
INPUT Name
ENDWHILE

//LENGTH() function is used here


INPUT Name
WHILE LENGTH(Name) = 0 DO
OUTPUT “No data given”
INPUT Name
ENDWHILE

v. Format check: It checks if the data follows a particular pattern or not. For example date format
will be DD/MM/YYYY or student ID must follow the format of 0000-000 where 0 is a digit. If
the data given is not according to the pattern set by the program then values will be asked to be re-

Page 2 of 6
entered. (Format check algorithm will be covered with STRING manipulation topic)

vi. Check digit (used only for numbers): Checks if the final digit of a string of numbers is correct
or not. The final digit of a string of numbers is calculated from all the other digits based on a
particular algorithm. That final digit is the check digit. If the number has been input wrongly then
the check digit will not match and the system will generate an error message.

The following validation checks may also be used:


vii. Limit check (used for numbers / dates): To check that the value is meeting only either the
upper limit or the lower limit. Only one limit is set here. For example, values should only be
accepted if they are greater than 50. So in this example, the lower limit of 50 is given but not
the upper limit.
viii. Character check: It accepts only the characters that are allowed in a scenario and rejects the
other characters. For example, For Gender field, only m, a, l, e or f, e, m, a, l, e, characters are
allowed and no other characters.
ix. Uniqueness check: Checks that data has been duplicated or not. For example, an email
address cannot be duplicated under the same domain.
x. Consistency check: When one field value is dependent on another field value then this check
is used. For example, there is a Title field and a Gender field. The Title field value will be
checked with Gender filed value. If the values of the two fields are not consistent then the
system will not accept the values. Suppose, in the Title field, the value is given as Mr. and in
the Gender field, the value is given as Female. There is an inconsistency in the values given as
a result system will not accept the values unless corrected.

Verification: Verification is a method that checks if the data has been accurately / correctly copied /
given into a computer system. This may or may not be automated.

Types of verification check during data entry:


i. Double entry
ii. Screen / Visual check

Double entry: For double entry the same data is entered twice, may be by the same operator or may be
by different operators. The computer system compares both entries and if they are different then outputs
an error message requesting for the data to be entered again. Entering password twice is an example of
double entry. Double entry verification is an automated checking by the program.

Pseudocode example:
//Take input of a password and ask the user to re-enter the same password. Allow the user to continue
until the same password is given. Display the number of times it took to enter the same password. Give
proper output and error message.

//Solution using WHILE loop


PasswordMatched ← FALSE // PasswordMatched is a FLAG variable
Count ← 0
OUTPUT “Enter your password: ”
INPUT Password1
WHILE PasswordMatched = FALSE DO
OUTPUT “Re-enter your password: ”
INPUT Password2
Count ← Count + 1
IF Password1 = Password2
THEN

Page 3 of 6
OUTPUT “Password matched. It took ”, Count, “attempts to match”
PasswordMatched←TRUE //This will stop the WHILE loop
ELSE
OUTPUT “Password did not match” //This will continue the WHILE loop
ENDIF
ENDWHILE

//Solution using REPEAT loop


PasswordMatched ← FALSE // PasswordMatched is a FLAG variable
Count ← 0
OUTPUT “Enter your password: ”
INPUT Password1
REPEAT
OUTPUT “Re-enter your password: ”
INPUT Password2
Count ← Count + 1
IF Password1 = Password2
THEN
OUTPUT “Password matched. It took ”, Count, “attempts to match”
PasswordMatched ← TRUE //This will stop the REPEAT loop
ELSE
OUTPUT “Password did not match” //This will continue the REPEAT loop
ENDIF
UNTIL PasswordMatched = TRUE

// Flag variable is used as a signal in programming to let the program know that a certain condition has
met. A flag variable is a variable you define to have one value until some condition is true or false in
which case you change the variable's value. It is a variable you can use to control the flow of a function
or statement, allowing you to check for certain conditions while your function executing.

Screen / Visual check: A screen / visual check is a manual check completed by the user who is entering
the data. When the data entry is complete the data is displayed on the screen and the user is asked to
confirm that it is correct before continuing. The user either checks the data on the screen against a paper
document that is being used as an input form or, confirms whether it is correct from their own
knowledge.

Practice questions
1. Which validation methods are being carried out by the following three pseudocode statements?

(i) if age> 10 and age < 20 then print "correct" ______________________________

(ii) if gender = "male" and title = "Mr." then print "correct" ____________________________

(iii) if field = "" then print "input data is missing" ______________________________

2. A program requires the user to type in a user ID which must be in the form: AA000000 where A
stands for any letter, and 0 stands for any digit.
(a) Name two possible validation checks that could be applied to this user ID.
______________________________

______________________________

Page 4 of 6
(b) Name a validation check that could not be used on this occasion. Give a reason for your
choice.
3. A hospital holds records of its patients in a database. Four of the fields are:
• date of visit (dd/mm/yyyy)
• patient’s height (m)
• 8-digit patient ID
• contact telephone number
The presence check is one possible type of validation check on the data. For each field, give
another validation check that can be performed. Give an example of data which would fail your
named validation check and also an example of data which would pass the validation check.
A different validation check needs to be given for each field.

Field Name Name of validation Example of data Example of data


check which would pass which would fail the
the validation validation check
check
Date of visit

Patient’s height

Patient ID

Contact telephone
number

Check Digit (A type of validation check) discussion


A check digit is the final digit in a string of numbers, calculated using all the other digits following a
particular algorithm. This is an automated error checking method by the system while data is being
entered into the system.
They are used for barcodes, product codes, International Standard Book Number (ISBN), Vehicle
Identification Number (VIN) etc.
They are used for identifying errors in data entry, for example mis-typing or mis-scanning a barcode.
They can usually detect the following types of error:
 an incorrect digit entered, e.g. 7823 instead of 7923
 transposition errors where two adjacent numbers have changed order, e.g. 4912 instead of 4192
 omitted a digit or an extra digit added, e.g. 426 instead of 4236 or 92573 instead of 9273
 Phonetic errors where people hear something and type something else

Example of check digit calculation:


An example of check digit calculation is ISBN-13 which follows modulo 10 methods. The check digit is
calculated as follows:
1. Add all the odd position digits together (i.e. starting from left, position of first digit will be 1,
second digit will be 2 and so on. In this case add the digits of 1st, 3rd, 5th position and so on)
2. Add all the even position digits together and multiply the result by 3. (Add the digits of 2nd, 4th,
6th position and so on and multiply the result by 3)
3. Add the results from 1 and 2 together and divide by 10 and take the integer remainder
Page 5 of 6
4. If the remainder is zero use the value as the check digit otherwise subtract the remainder from
10 to find the check digit.
5. For example 50/10, quotient is 5 and remainder is 0. So check digit will be 0. Another example,
76/10, quotient is 7 and remainder is 6. So the check digit will be 10-6 = 4

To verify if a check digit is correct the check digit has to be used as the last digit in the same algorithm
and after the entire process if the remainder becomes zero then the check digit will be regarded as correct
otherwise not.

Another example of check digit calculation is ISBN-10 which follows Modulo-11 method. The modulo-
11 method can have varying lengths of number which makes it suitable for many applications, such as
product codes or VINs. The check digit is calculated as follows:
1. the weighted value of each digit is first considered (The weighted values will be given)
2. Each digit in the number is then multiplied by its weighted value and the totals are added
together
3. The total is then divided by 11 (modulo 11) and the integer remainder is taken
4. If the remainder is zero (0) then this will be the check digit otherwise the remainder will be
subtracted from 11 to obtain the check digit. The remainder can be 10 as maximum.
5. After the subtraction from 11, if the check digit is calculated as 10 then it is represented by the
letter X.
6. For example 55/11, quotient is 5 and remainder is 0. So check digit will be 0. Another example,
59/11, quotient is 5 and remainder is 4. So the check digit will be 11-4 = 7. Another example,
43/11, quotient is 3 and remainder is 10. So the check digit will be 11-10 = 1. Another example,
45/11, quotient is 4 and remainder is 1. So the check digit will be 11-1 = 10, which will be
represented by the letter X.

To verify if a check digit is correct the check digit has to be used as the last digit in the same algorithm
and after the entire process if the remainder becomes zero then the check digit will be regarded as correct
otherwise not.

Usually in the question paper, the algorithm is given to perform check digit which must be followed to
answer properly. Check digit is always part of validation checking and not verification checking. Check
digit topic may appear in paper 1 (chapter 2) as well as in paper 2.

Page 6 of 6

You might also like