You are on page 1of 9

7 Algorithm design and problem-solving

Need for validation checks to be made on input data and types of validation checks

• In order for computer systems to only accept data inputs that ere reasonable and accurate, every item of
data needs to be examined before it is accepted by the system.
• Two different methods are use in data entry.
- Validation ensures that only data that is reasonable is accepted.
- Verification is used to check that the data does not change as it is being entered.
Validation
• Validation is the automated checking by a program that data is reasonable before it is accepted into a
computer system.
• When data is validated by a computer system, if the data is rejected a message should be output explaining
why the data was rejected and another opportunity given to enter the data.
• There are many different types of validation checks including;
- Range checks
- Length checks
- Type checks
- Presence checks
- Format checks
- Check digits
• Different types of check may be used on the same piece of data;
Ex. An examination mark could be checked for reasonableness by using a range check, type check and a
presence check
• This is used in your program as follows.

Range check
A range check checks that the value of a number is between an upper value and a lower value.
Ex. Checking that percentage marks are between 0 and100 inclusive:

1
7 Algorithm design and problem-solving

Length check
A length check checks either;
That data contains an exact number of characters;
Ex. That a password with seven or fewer characters or nine or more characters would be rejected, for
instance:

Or
That the data entered is reasonable number of characters,
Ex. A family name could be between two and thirty characters inclusive so that names with one character
or thirty-one or more characters would be rejected.

Type check
A type check checks that the data entered is of a given data type.
Ex. That the number of brothers or sisters would be an integer (whole number)

2
7 Algorithm design and problem-solving

Presence check
A presence check checks to ensure that some data has been entered and the values has not been left
blank.
Ex. An email address for an online transaction must be completed.

Format check
A format check checks that the characters entered confirm to a pre-defined pattern.
Ex. Any code / ID number must be in the form of CUB9999.

Check digit
Is the final digit included in a code; it is calculated from all the other digits in the code. Check digits are
used for barcodes, product codes, International Standard Book numbers (ISBN) and vehicle Identification
Numbers(VIN)
Check digits are used to identify errors in data entry caused by mis-typing or mis-scanning a barcode.

They can usually detect the following types of errors:


- An incorrect digit entered
Ex. 5327 entered instead of 5307
- Transposition errors where two numbers have changed order
Ex. 5037 entered instead of 5307
- Omitted or extra digits entered
Ex. 537 instead of 5307 or 53107 instead of 5307
- Phonetic errors
Ex 13, thirteen instead of 30, thirty

3
7 Algorithm design and problem-solving

In Databases we use the above mentioned Validation checks when designing tables.
Below given are how the above validations are implemented in databases.

1. Presence check makes sure that data is present in a field where it is compulsory that a value be entered.
For example, information about a student would be of little use without including an identifier such as
the student’s Admission Number.

Required: Yes
(Presence check)

2. Range checks are used to check that data is within a certain range of numbers or a specific set of values.
For example if the examination marks for a group of students were being input, a range check could be
used to make sure each mark was greater than or equal to zero and less than or equal to the maximum
possible mark.

Range Check

4
7 Algorithm design and problem-solving

3. Length checks

Length Check

4. Data Type checks to ensure a data item is of a particular data type.


For example number of items in stock will be entered as integer; no numbers are entered in a name field.

Field Name Type Valid Data Invalid Data

Date of Birth Date 11/03/96 30/02/76, fred

Sex Alphabetic Male, Female, Albert 123, WA2

Shoe Size Numeric 12, 2.3, 12323 6G, house

Name Alphabetic Willson 5ofia

5
7 Algorithm design and problem-solving

Data type check

5. Format checks to ensure a data item matches a previously determined pattern and that particular
characters have particular values such as being letters or digits.
0 - A number must be typed in this position.
9 - A number may be typed in this position or it may be left blank.
L - A letter must be typed in this position.
l - A letter may be typed in this position or it may be left blank.
A - A letter or number must be typed in this position.
a - A letter or number may be typed in this position or it may be left blank.

6
7 Algorithm design and problem-solving

Verification
• Verification is checking that data has been accurately copied from one source to another – for instance, input
into a computer or transferred from one part of a computer system to another.
• Verification methods for input data include:
- Double entry
- Screen / visual checks

Double entry
- For double entry that data is entered twice, some times by different operations.
- The computer system compares both entries and if they are different outputs an error message
requesting that the data is entered again.

Screen / visual check


- A screen or 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 check 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.

7
7 Algorithm design and problem-solving

Database Validations - Practise exercise

British School in Colombo is planning for a drama production. The school needs a database to store
information of the cast and the costumes. You have been assigned to create a database.

1. Open a new database and name it as dbBSCDrama.


2. Create the tables according to the information given below.

tblCast
Field name Data Type
Admission Number Number
Name Text
Gender Text
Class Text
Character Text
Contact Number Text
E-mail address Text
Date Joined Date/Time

tblCostumes
Field name Data Type
Costume Number Number
Admission Number Number
Colour Text
Size Number
Price Currency

3. Apply the following validation rules and write the validation rule in the space provided.

(a) Enter a presence check for Admission Number.

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

(b) Enter a presence check for Costume Number

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

(c) Contact Number must be 10 digits

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

8
7 Algorithm design and problem-solving

(d) Format check for Date Joined.

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

(e) Size Should be between 1 and 5.

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

(f) Create a look up for Gender.

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

(g) Price should be between 1000 and 5000 inclusive.

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

(h) Name must only have alphabets.

……………………………………………………………………………………………………….

……………………………………………………………………………………………………….

4. Enter 5 records in tblCast and tblCostumes separately.

You might also like