Validation
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.
Range check
• A range check checks that the value of a
number is between an upper value and a
lower value. For example, checking that
percentage marks are between 0 and
100 inclusive:
Range check
Length check
A length check checks either:
• that data contains an exact number of
characters, for example that a password must
be exactly eight characters in length so that
passwords with seven or fewer characters or
nine or more characters would be rejected, for
instance:
• or that the data entered is a reasonable number
of characters, for example, 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, for example, that the
number of brothers or sisters would be an
integer (whole number).
Presence check
• A presence check checks to ensure that some
data has been entered and the value has not
been left blank, for example, an email address
for an online transaction must be completed.
Format check
• A format check checks that the characters
entered conform to a pre-defined pattern.
Check digit
• A 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 error:
• an incorrect digit entered, for example, 5327
entered instead of 5307
• transposition errors where two numbers have
changed order for example 5037 instead of 5307
• omitted or extra digits, for example, 537 instead of
5307 or 53107 instead of 5307
• phonetic errors, for example, 13, thirteen, instead of
30, thirty.
ISBN 13 code with check digit
An example of a check digit calculation is ISBN
13, where the 13th digit of the ISBN code is
calculated using the following algorithm.
• Add all the odd numbered digits together,
excluding the check digit.
• Add all the even numbered digits together and
multiply the result by 3
• Add the results from 1 and 2 together and
divide by 10.
• Take the remainder, if it is zero use this value,
otherwise subtract the remainder from 10 to
find the check digit.
Using the ISBN above 9 7 8 0 3 4 0 9 8 3 8 2
without its check digit:
• 9 + 8 + 3 + 0 + 8 + 8 = 36
• 3 (7 + 0 + 4 + 9 + 3 + 2) = 75
• (36 + 75)/10 = 11 remainder 1
• 10 – 1 = 9 the check digit.
To check that an ISBN 13 digit code is
correct a similar process is followed.
• Add all the odd numbered digits together,
including the check digit.
• Add all the even number of digits together
and multiply the result by 3.
• Add the results from 1 and 2 together and
divide by 10.
• The number is correct if the remainder is zero.
Using the ISBN above 9 7 8 0 3 4 0 9 8
3 8 2 9 with its check digit:
• 9 + 8 + 3 + 0 + 8 + 8 + 9 = 45
• 3(7 + 0 + 4 + 9 + 3 + 2) = 75
• (45 + 75)/10 = 12 remainder 0
• Remainder is 0 therefore number is correct.
Seatwork:
• Find the check digit for the ISBN
978190612400.
• Are these ISBNs correct?
- 9718780171500
- 9781234567897
Seatwork
Which validation checks could you use for the
following? You may decide that more than one
validation check is required.
a. Entering a telephone number.
b. Entering a student’s name.
c. Entering a part number in the form XXX999,
where X must be a letter and 9 must be a
digit.