teach-ict.com logo

THE education site for computer science and ICT

3. Validation: Presence

Any time that a program asks the user for information, there is a chance that the user will input fillersomething unexpected. Well written, robust programs should be able to deal with the input data, checking that the inputs match expectations and rejecting those which do not.

This is called data validation, and we will go over some of the basic checks that you are expected to be able to reproduce in your own programs.

Presence validation

The most basic type of data validation is the presence check. This type of validation does not care about the contents of the data, it just ensures that the input was not entirely blank.

	SET pass TO ''
	WHILE pass = '' DO
	 SEND ('Enter password') TO DISPLAY

In the section on sequence, selection, and iteration, we talked about how WHILE loops need a condition to check. The first line of the above pseudocode sets the initial condition which is a blank password variable, named 'pass'.

The loop prompts the user to enter a password, and accepts their input. So long as the 'pass' variable remains blank, the loop will continue. Once the user types any kind of password using the keyboard, the presence check is passed and the loop ends.


Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is data validation?