Validation (CIE IGCSE Computer Science)

Revision Note

Test Yourself
Dan Turnes

Expertise

Computer Science

Validation

  • Validation and verification are used to ensure input data is correct, reasonable and accurate
  • Validation generally is about making sure data follows a set of specified rules created by the programmer. Verification is about double-checking input data to make sure it's what the user intended to enter

Validation

  • Validation is the method of checking input data so that it is of an expected value and therefore accepted by the system
  • Programmers create rules using code that automatically checks user input data to make sure the data is reasonable. If it is not reasonable then the data is rejected, usually with a message explaining why it was rejected and allowing the user to reenter the data
  • The different types of validation rules or checks are as follows:
    • Range checks
    • Length checks
    • Type checks
    • Presence checks
    • Format checks
    • Check digits
  • Each piece of data may require multiple different checks to be fully valid

Range check

  • Range checks make sure the input data is a value between a user-defined minimum and maximum value, for example, a percentage being between 0 and 100 inclusive or a date in April is between 1 and 30 inclusive

OUTPUT “Enter a number between 0 and 100”

REPEAT

INPUT Number

IF Number < 0 OR Number > 100 

  THEN

OUTPUT “Number is not between 0 and 100, please try again”

ENDIF

UNTIL Number >= 0 AND Number <= 100

Length check

  • Length checks check either that the input data is of an exact number of characters or in a user specified number range of characters
  • A bank 4-digit PIN number may be an example of an exact number of characters. If it is not 4 digits in length it should be rejected

OUTPUT “Please enter your 4 digit bank PIN number”

REPEAT

INPUT Pin

IF LENGTH(Pin) <> 4 

THEN

OUTPUT “Your pin number must be four characters in length, please try again”

ENDIF

UNTIL LENGTH(Pin) = 4

  • Passwords usually have a specified range, for example, eight to twenty characters in length. If it does not fall within this range, it should be rejected

OUTPUT “Please enter a password between 8 and 20 characters”

REPEAT

INPUT Password

IF LENGTH(Password) < 8 OR LENGTH(Password) > 20 

THEN

OUTPUT “Your password must be between 8 and 20 characters in length, please try again”

ENDIF

UNTIL LENGTH(Password) >= 8 AND LENGTH(Password) <= 20

Type checks

  • Type checks make sure the input data is of the correct data type. For example, someone's age should be an integer (a whole number) whereas their name should be a string (a bunch of characters)

OUTPUT “Enter an integer number”

REPEAT

INPUT Number

IF Number <> DIV(Number, 1)

  THEN

OUTPUT “Not a whole number, please try again”

ENDIF

UNTIL Number = DIV(Number , 1)

Presence check

  • Presence checks make sure that input data has been entered and that the input box has not been left empty
  • A login system requires presence checks as both a username and password are required for authentication

OUTPUT “Enter your username”

REPEAT

INPUT Username

IF Username = “” 

THEN

OUTPUT “No username entered, please try again”

ENDIF

UNTIL Username <> “”

Format check

  • Format checks make sure that input data is of a predefined pattern
  • Identification codes e.g. AP1234 and dates are examples of patterns
  • Format checks are done using pattern matching and string handling
  • The algorithm below checks a six digit identification number against the format “XX9999” where X is an uppercase alphabetical letter and 9999 is a four digit number
  • The first two characters are checked against a list of approved characters. The first character is compared one at a time to each valid character in the ValidChars array. If it finds a match it stops looping and sets ValidChar to True. The second character is then compared one at a time to each valid character in the ValidChars array. If it finds a match then it also stops looping and sets ValidChar to True
  • Casting is used on the digits to turn the digit characters into numbers. Once the digits are considered a proper integer they can be checked to see if they are in the appropriate range of 0-9999
  • If any of these checks fail then an appropriate message is output

INPUT IDNumber

IF LENGTH(IDNumber) <> 6

  THEN

OUTPUT “ID number must be 6 characters long”

END IF

ValidChars ← “ABCDEFGHIJKLMNOPQRSTUVWXYZ”

FirstChar ← SUBSTRING(IDNumber, 1, 1)

ValidChar ← False

Index ← 1

WHILE Index <= LENGTH(ValidChars) AND ValidChar = False DO

IF FirstChar = ValidChars[Index] 

  THEN

ValidChar ← True

ENDIF

Index ← Index + 1

ENDWHILE

IF ValidChar = False

  THEN

OUTPUT “First character is not a valid uppercase alphabetical character”

ENDIF

SecondChar ← SUBSTRING(IDNumber, 2, 2)

ValidChar ← False

Index ← 1

WHILE Index <= LENGTH(ValidChars) AND ValidChar = False DO

IF SecondChar = ValidChars[Index] 

  THEN

ValidChar ← True

ENDIF

Index ← Index + 1

ENDWHILE

IF ValidChar = False

  THEN

OUTPUT “Second character is not a valid uppercase alphabetical character”

ENDIF

Digits ← INT(SUBSTRING(IDNumber, 3, 6))

IF Digits < 0000 OR Digits > 9999

  THEN

OUTPUT “Digits invalid. Enter four valid digits in the range 0000-9999”

ENDIF

Check digits

  • Check digits are numerical values that are the final digit of a larger code such as a barcode or an International Standard Book Number (ISBN). They are calculated by applying an algorithm to the code and are then attached to the overall code
  • Check digits help to identify errors in data entry such as mistyping, miscanning  or misspeaking 
    • Such errors include missing or additional digits, swapped digits, mispronunciation of digits or simply an incorrect digit

Barcode ← “9780201379624”

Total ← 0

FOR Index = 1 to LENGTH(Barcode) - 1

IF Index MOD 2 = 0 

THEN

Total ← Total + CAST_TO_INT(Barcode[Index])*3

ELSE

Total ← Total + CAST_TO_INT(Barcode[Index])*1

ENDIF

NEXT Index

CheckDigit ← 10 - Total MOD 10

 

IF CheckDigit = Barcode[LENGTH(Barcode)] 

  THEN

OUTPUT “Valid check digit”

ELSE

OUTPUT “Invalid check digit”

ENDIF

Verification

  • Verification is the act of checking data is accurate when entered into a system
  • Mistakes such as creating a new account and entering a password incorrectly mean being locked out of the account immediately
  • Verification methods include: double entry checking and visual checks

Double entry checking

  • Double entry checking involves entering the data twice in separate input boxes and then comparing the data to ensure they both match. If they do not, an error message is shown

REPEAT

OUTPUT “Enter your password”

INPUT Password

OUTPUT “Please confirm your password”

INPUT ConfirmPassword

IF Password <> ConfirmPassword 

THEN

OUTPUT “Passwords do not match, please try again”

ENDIF

UNTIL Password = ConfirmPassword

Visual check

  • Visual checks involve the user visually checking the data on the screen. A popup or message then asks if the data is correct before proceeding. If it isn’t the user then enters the data again

REPEAT

OUTPUT “Enter your name”

INPUT Name

OUTPUT “Your name is: “, Name, “. Is this correct? (y/n)”

INPUT Answer

UNTIL Answer = “y”

Worked example

Describe the purpose of validation and verification checks during data entry. Include an example for each. 

[4]

Validation check 

[1] for description: 

  • To test if the data entered is possible / reasonable / sensible
  • A range check tests that data entered fits within specified values

[1]  for example: 

  • Range / length / type / presence / format

Verification check 

[1]  for description: 

  • To test if the data input is the same as the data that was intended to be input
  • A double entry check expects each item of data to be entered twice and compares both entries to check they are the same

[1]  for example: 

  • Visual / double entry

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Dan Turnes

Author: Dan Turnes

Dan graduated from the University of York with a BEng in Computer Science and has been a teacher and tutor of GCSE and A-Level Computer Science in the Yorkshire area for over six years. His goals are to engage students in the science of learning and to enable them to enjoy the experience. Dan's continued practice has brought him to SME to create high quality resources and support students to achieve their potential in Computer Science.