Validation is the process of checking that input data is reasonable. Validation does not and cannot check that inputs are accurate.
An existence check checks whether a value has been entered at all. This is particularly useful to ensure that all required fields in a form have been completed before saving the contents of those fields to a file.
A type check is a useful method of confirming that the values entered into fields are of the expected data type. It will confirm if the wrong type of data has been entered in fields, such as if strings are entered into fields that expect only integer values.
When implementing type checking, it is important to consider how inputs from a user are processed by the selected programming language. For example, in Python, unless explicitly handled otherwise, all inputs are treated as strings, even if they are numeric. In languages such as these, there typically exists methods for checking type, such as the process of casting the data as a particular data type to see if it remains valid.
A range check checks that data is within acceptable limits or comes from a range of acceptable values. For example, students enrolling in kindergarten must be between the ages of 3 and 6 years (acceptable limits). As another example, the product size must be small, medium or large (acceptable values).
START validate_input
IMPORT data
# Existence Check
IF data IS None DO
RETURN FALSE and "Data does not exist"
ENDIF
# Type check
IF data is NOT instance of integer DO
RETURN FALSE and "Data is not an integer"
ENDIF
# Range check
IF data IS NOT between 0 and 100 DO
RETURN FALSE and "Data is out of range. It should be between 0 and 100"
ENDIF
RETURN TRUE and "Data is valid"