Validation
Validation
Please note that none of these pseudocode examples are 100% correct (referring to syntax - as
in the technical way to write it) but the idea is to show you how the methods work.
Validation
This an automated process where a computer checks if input value by the
user meets the program's requirements to run (e.g. if a str variable is used,
it makes sure that the user enters a string not an integer, Boolean or a
float/real value so that the program can run without errors).
There are 6 main ones you need to know (range, length, type, present,
format checks, and check digits)
Range Check
Copy
OUTPUT 'Input any number between 0 and 100 inclusive'
REPEAT
INPUT Number
IF Number < 0 OR Number > 100
THEN
OUTPUT 'Your number is not between 0 and 100 inclusive.
Try again.'
ENDIF
UNTIL Number >= 0 AND Number <=100
Length Check
This will check the length of a string (e.g. a password to ensure that its at
least 8 characters long)
Copy
OUPUT 'Please enter your password'
REPEAT
INPUT Password
IF LENGTH(Password) < 8
THEN
OUTPUT 'Your password is too short. Try again.'
ENDIF
UNTIL LENGTH(Password) <- 8
Type Check
This will check what type of data you've entered whether it's a Boolean,
string, or integer.
Copy
OUTPUT 'Enter an integer'
REPEAT
INPUT Number
IF Number <> DIV(Number, 1)
THEN
OUTPUT 'You have not entered an integer. Try again.'
ENDIF
UNTIL Number <- DIV(Number, 1)
Presence Check
Checks to see if you've entered data into a field or not (e.g. required * fields
on an online form)
Copy
OUTPUT 'Enter your age'
REPEAT
INPUT Age
IF Age = ''
THEN
OUTPUT 'You need to enter your age'
ENDIF
UNTIL Age <> ''
Format Check
This will ensure that data has been inputted in the correct format (e.g. say
you want their date of birth, but you want the day first, then the month, then
the year). It's done using pattern matching and string handling.
Copy
OUPTUT 'Enter your gmail email address'
Run <- True
WHILE Run = True DO
INPUT Email
IF '@gmail.com' NOT IN Email
THEN
OUTPUT 'You have not entered a gmail email address. Try
again.'
ELIF '@gmail.com' IN Email
THEN
Run <- False
ENDIF
ENDWHILE
Check Digits
If you're unsure about what these are, look here as I've explained them
already.
Verification
This is to check whether data is accurate or not when entered into a
system. There are two main methods which you need to be aware of
(double entry checking and visual checks).
This involves entering the data twice (e.g. when resetting a password or
entering your email). You have to input data into two seperate variables
and then check both to see if they match. If they do not match, then both
inputs are not the same, so the user has incorrectly entered data.
Copy
REPEAT
OUTPUT 'Enter your password'
INPUT Password1
OUTPUT 'To confirm your password, please enter it again'
INPUT Password2
IF Password1 <> Password2
THEN
OUTPUT 'Your passwords do not match. Try again.'
ENDIF
UNTIL Password1 = Password2
Visual Checks
This is where you trust the human to check the data they're inputting
without any actual data checking via an algorithm or check.
A pop-up should appear before they are allowed to enter the data. If they
select that the data is correct, then the data is appended to the variable. If
not, then the data is re-inputted before being appended to the variable.
Copy
REPEAT
Answer <- False
OUTPUT 'Enter your name'
INPUT Name
OUTPUT 'Is this correct (Y/N)?'
INPUT Verify
IF Verify = 'N'
THEN
OUTPUT 'Please re-enter the data'
INPUT Name
ELIF Verify = 'Y'
THEN
Answer <- True
ENDIF
UNTIL Answer <- True
Test Data
There are 4 types of test data: