Input Validation Flashcards
Card 1 of 9
All 9 cards in this deck
What is input validation?
A check that only sensible/allowed data is entered into a program, e.g. restricting a rating to 1 to 10.
What does a range check do?
e.g. a height in cm must be from 40 to 180Checks the value entered lies between a stated lower and upper limit — here, that the height is at least 40 and no more than 180.
What does a presence check do?
Checks that data has actually been entered and the field has not been left blank.
What does a length check do?
Checks that the data entered has an allowed number of characters, e.g. a password of at least 8 characters.
What does a type check do?
Checks that the data entered is of the correct data type, e.g. an integer for an age.
What does a format check do?
Checks that the data entered follows a set pattern, e.g. a postcode or a date as dd/mm/yyyy.
What should a program do when it detects invalid data?
Reject the data, output a helpful error message and ask the user to enter it again, rather than crashing or storing it.
True or false?
if height >= 40 AND <= 180is an acceptable way to write a range check.False. The variable must be repeated in each condition:
if height >= 40 AND height <= 180.What does a look-up check do? (e.g. a T-shirt size must be S, M, L or XL)
Compares the data entered with a list (table) of allowed values and rejects it if it isn't in the list — here, any size other than S, M, L or XL.