Validation
validationChecking input data is sensible and in the right format. is used to assess whether dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions. entered into a system is reasonable. It cannot tell if the data is correct, but it can check to see if it is within the acceptable parameters for valid data.
Techniques of validating data
A programmer should consider that any inputData which is inserted into a system for processing and/or storage. a user makes may be incorrect and should plan for such mistakes. Using validation helps a programmer to ensure that any data input is possible and sensible.
Validation applies rules to input data. If the data does not follow the rules it is rejected, reducing the risk of invalid data crashing a program.
A programmer can build various types of validation into a program:
- Range check - the input must fall within a specified range. This is usually applied to numbers and dates, but can apply to characters. For example, when making a payment to someone, the amount to be entered might be set to be greater than zero and not greater than the funds available.
- Length check - the input must not be too long or too short. For example, a surname will require at least one letter but is unlikely to require more than 40.
- Presence check - a data value must be entered. For example, entering a quantity when placing an order.
- Format check - the data must be in the correct format, such as entering a date in the format DD/MM/YYYY.
- Type check - the data must be of a specified data type, such as an integer when specifying a quantity.
- Lookup table - this allows the user to pick one item from a specified pre-defined list.
- Check digit - often used on identification numbers such as bank account details to ensure the numbers have been entered correctly.
Many programs use one or more of these validation checks. For example, when signing up for a user account on a website the validation might include one or all of the following:
- presence check - a username must be entered
- length check - a password must be at least eight characters long
- range check - age restrictions may require the user's date of birth to be before a certain date
- format check - the user's date of birth must be entered in the specified format
- type check - the password may need to have a mixture of upper and lower case letters, a number and a special character
- lookup check - the item selected must be from a pre-defined list of valid entries
Validation does not ensure that the data entered is correct, just that it is possible and sensible. A user may accidentally enter a date of birth that is possible and sensible, but incorrect. The program has no way of knowing that the date has been entered incorrectly.
To get around this, many programs include authenticationVerifying the identity of a user. checks - they repeat the entered data to the user and ask them to confirm if this data is correct. If the user confirms the data, the program then assumes it to be correct. This is an example of how planning the design of a program can help reduce errors.
Validation can be very simple. This example uses a range check. The program will keep repeating the instruction until valid data has been entered:
number is integer
tryAgain is boolean
set tryAgain = TRUE
while tryAgain == TRUE
input 鈥淓nter a number between 0 and 10鈥, number
if number >=0 AND number <=10
output 鈥淭hank you鈥
set tryAgain = FALSE
else
output 鈥淚nvalid data entered, try again鈥
end if
end while