A data set is no use if it contains incorrect data. As far as possible, it is best to avoid inputting invalid data in the first place. Most mistakes can be prevented by setting the software to reject certain values that are unacceptable. This happens at the time of input.
Data validation aims to make sure that data is sensible, reasonable, complete and within acceptable boundaries.
For example, a secondary school student is likely to be aged between 11 and 16. The computer can be programmed only to accept numbers between 11 and 16. This is a range check.
However, this does not guarantee that the number typed in is correct. For example, a student's age might be 14, but if 11 is entered it will be valid but incorrect.
Typical Validation Checks:
|Type Check||Ensures that data entered is of the correct type||Rejecting non-numeric characters when entering a persons age.|
|Range Check||Ensures that data entered falls between a specific range||Rejecting numbers that are not between 0 and 100 when entering a percentage.|
|Length Check||Ensures that data entered has a specific number of characters||Checking that all digits of a telephone number or post code have been entered.|
|Presence Check||Ensures that some data has been entered (field cannot be left blank)||Checking that an email address has been entered when completing a contact form.|
|Format Check||Ensures that data matches a specific format||e.g. postcode would have the format: LL## #LL (Letters & # numbers)|
#Program to capture user name and check name is between 2 and 20 characters name = input("Please enter name: ") while (name.length < 2) OR (name.length> 20) print("Must be between 2 and 20 characters - please re-enter: ") name = input("Please enter name: ") endwhile
#How to make sure the user enters a number (integer) def inputNumber(message): while True: try: userInput = int(input(message)) except ValueError: print("Not an integer! Try again.") continue else: return userInput break #MAIN PROGRAM STARTS HERE: age = inputNumber("How old are you?") if (age>=18): print("You are old enough to vote.") else: print("You will be able to vote in " + str(18-age) + " year(s).")
There are two main methods of verification:
Validation and verification are two ways to check that the data entered into a computer is correct. Data entered incorrectly is of little use.