Bits of Bytes.co

IGCSE / GCSE Computer Science

  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
Picture
MENU
  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
2 - Practical Problem Solving & Programming / Validation


Validation and Verification


Validation  and Verification are both used to ensure that data entered into a computer system is correct and reasonable.  The use of both Validation and verification is vital for the smooth running of computer systems.

Validation


​Validation is a process that checks that data is reasonable before it is accepted by a computer system. Validation is automated meaning that a well designed algorithm should successfully decide whether or not data is acceptable.

There are a number of different Validation checks that can be performed on data. These include:
  • Range Checks
  • Presence Checks
  • Format Checks
  • Type Checks
  • Character Checks
  • Check Digits

Each of these checks are explained in more detail below:
​

Range Checks

A range check is used to ensure that numbers are only accepted into a program if it falls within a certain acceptable range.

Example - If a program asks for somebodies age then you might limit entries to be between 13 and 100.  This would potentially prevent people under the age of 13 from signing up and it would also prevent people giving an unrealistic age e.g. 250 years old.

Pseudo code for a validation check like this may look like:

Age = 0
OUTPUT "Please enter your age"
Age = INPUT()
WHILE Age < 13 OR Age > 100 DO
     IF Age < 13 THEN
          OUTPUT "Sorry, you are too young"
     ELSE IF Age > 100 DO
          OUTPUT "Sorry, Age entered is not realistic - it is too high"
    END IF
    OUTPUT "Please re-enter your age"
    Age = INPUT()
END WHILE


​You can test this out yourself using the Python Trinket below...

The above code works do validate the age through the use of a WHILE loop.  The user will not be allowed to progress to the next part of the program until the age lies between 13 and 100 (A REPEAT UNTIL loop could also be used). Of course this program is not perfect as a 10 year old would simply get a chance to enter their age again and lie about it, however the code should illustrate the practical implementation of a range check.

Presence check

A Presence check is used to ensure that some data has been entered. This is used where you cannot allow the user to progress until they provide you with information e.g. a user cannot sign up to a service if they have left the e-mail field empty.

Example - An internet blog has the ability to post comments. You do not need to create an account, however before the post is published you do need to enter your name. In this case there are no rules about how long your name should be, or even that it has to be realistic. The only rule is that you have to enter a name.

Pseudo code for a validation check like this may look like:

Name = ""
OUTPUT "Please enter your name so that we can post your comment"
Name = INPUT()
WHILE Name = "" DO
     OUTPUT "Sorry, You must enter a name before your post can be published"
     Name = INPUT()
END WHILE

OUTPUT "Thank you " + Name + "  Your comment has been published"

​You can test this out yourself using the Python Trinket below. Try testing what will happen when you enter nothing vs when you enter a name.

The above code works to validate the presence of a name through the use of a WHILE loop.  The user will not be allowed to progress to the next part of the program until the Name variable contains data. Whilst the Name variable remains empty the user will be asked to enter a name. (A REPEAT UNTIL loop could also be used).

Format Check

A format check is used to ensure that data entered matches a desired pattern. e.g. if a user is required to enter an email address then 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 of a format check would be to check that an ID number has been entered in the correct format.  Lets imaginge that in our program an ID number must begin with the organisations initials ISS and must end with 4 numbers e.g ISS1432.

Pseudo code for a validation check like this may look like:

OUTPUT "Please enter an ID number e.g. ISS1111"
Accepted = False
While Accepted = False Do:
​     
IDNo = INPUT()
     First = IDNo[0,1,2]
     Last = IDNo[3,4,5,6]
     Length = Len(IDNo)

     IF Length =7 THEN AND First = "ISS" AND (Last >=0000 AND Last <=9999):
        Accepted = TRUE
     ELSE:
          OUTPUT "ID Not acceptable - Please try again"
     END IF
END WHILE
OUTPUT "Acceptable ID no entered.
     

​You can test this out yourself using the Python Trinket below. Try testing what will happen when you enter a valid or invalid ID Number. This example is case sensitive - the ISS must be capitol latters to be accepted.

The above code works but it could be improved.  Currently it does not let the user know why the code that they entered was incorrect. It would be possible to break down the IF statement into nested IFs so that the user could be provided with helpful prompts e.g. "Your ID number does not start with "ISS""

Type Check

 A Type check is used to ensure that the correct data type has been entered. This means that  if you are requesting an integer then the program will only accept an integer, a string or any other data type would be rejected.

An example scenario for this would be a program that asks the user to enter their age. This input should be a whole number and therefor an integer. If any other type of data is entered then it should be rejected and the user should be given the chance to try again.

Pseudo code for a validation check like this may look like:

OUTPUT "Please enter your age"
Accepted = False
While Accepted = False Do:
​     
Age = INPUT()
     
IF Age.isdigit():
        Accepted = TRUE
     ELSE:
          OUTPUT "Age Not acceptable - Must be a whole number"
     END IF
END WHILE
OUTPUT "Acceptable Age entered.
     

​You can test this out yourself using the Python Trinket below. ​Try testing what will happen when you enter a string or a decimal number.
In the real world this solution would need to be validated further. You might want to add a range check to it to ensure that a realistic age is entered e.g. a max age of 100.

Character Check

 A Type check is used to ensure that an entered string does not contain any unacceptable characters. 

An example scenario might be that a user needs to choose a username. The username cannot contain the ! or @ symbol as they are reserved for admin usernames.

Pseudo code for a validation check like this may look like:

OUTPUT "Please choose a username"
Accepted = False
Find = False
While Accepted = False Do:
​     
Username = INPUT()
     
length = len(Username)
     FOR x = 0 to Length DO:

          IF Username(x) = "!" OR Username(x) = "@"
               Find = True
          END IF
      END FOR

      IF Find = True THEN:
          Accepted = False
          Find = False

          OUTPUT "Unacceptable Username, cannot contain ! or @ symbols"
          Else:
               Accepted = True
          END IF
END WHILE
OUTPUT "Acceptable username entered"

​
     
​You can test this out yourself using the Python Trinket below. ​Try testing what will happen when you enter a username that contains the symbols ! or @ then test what happens when you enter an acceptable username.

Verification


Verification differs to Validation. Its purpose is not to judge that realistic / acceptable  data has been entered but rather the purpose of Verification is to ensure that data that has been entered into a computer is correct.

There are 4 Verification methods to be aware of at this stage, these are:
  • Visual Checking
  • Double entry verification
  • Parity Checks
  • Check sums
Parity checks and Checksums are discussed in the error checking section

Visual Checking

 A visual data check is as simple as it sounds. It is a very manual / human way of checking which involves a user manually reading through data to ensure that it is correct.

It is also possible that another person can be asked to read through the data to check for mistakes. This is similar to proof reading. If a mistake is spotted then the data can be changed.
Picture

Double Entry Verification

Double entry verification works by asking the user to enter data twice. The two pieces of data will then be compared. If the two entered pieces of data do not match then a mistake has been detected. The user will now be asked to enter the data again.

A common example scenario for this is when choosing a password to sign up for an online service. It is important that during this process a mistake is not made.  If the user war trying to set their password as "Apple" but accidentally misspelled it as "Appple" then they may struggle to access their account.
To avoid this, new members are asked to enter their chosen password twice. The chances of accidentally misspelling the password twice in the exact same way are slim and therefor this reduces the chance of inaccurate data being entered.
Picture
Est. 2015 - Copyright © 2020