Skip to content
IGCSE·Tuition
Computer Science · Lesson

Choose a validation rule from a requirement

A question gives you a sentence about what a program must accept, and you have to name the exact check that enforces it.

On this page
  1. Which check matches which requirement?
  2. Worked example
  3. The mistake to watch for
  4. Check yourself
  5. Where does this lead next?

Validation is an automatic check that data is reasonable and allowed before a program uses it. In exam questions you are usually given a requirement in plain words and asked to name the check or write it. The skill is matching the wording of the requirement to the right type of check.

This is the first lesson of the validation, verification and testing module.

Which check matches which requirement?

Read the requirement and find the key word. It tells you the check.

Requirement wordingCheckWhat it tests
“must be between 13 and 17”Range checkValue lies within lower and upper limits
“at least 8 characters”Length checkNumber of characters
“must be a whole number”Type checkData is the correct data type
“must not be left empty”Presence checkSomething has been entered
“two letters then three digits”Format checkCharacters follow a set pattern

A check digit is another validation method, used for numbers such as barcodes. It is covered with data checking in data transmission and checking.

Worked example

A fictional school club asks for a member’s age. The requirement says: “Age must be a whole number from 13 to 17 inclusive.”

Step 1, find the key words. “Whole number” is about data type. “From 13 to 17” is about limits.

Step 2, name the checks. A type check (integer) and a range check.

Step 3, write the range check. Keep asking until the value is accepted:

REPEAT
  INPUT Age
  IF Age < 13 OR Age > 17 THEN
    OUTPUT "Age must be 13 to 17"
  ENDIF
UNTIL Age >= 13 AND Age <= 17

Step 4, trace it with the inputs 20, 12, 15.

InputAge < 13 OR Age > 17MessageUNTIL true?
20TRUE (20 > 17)shownNo
12TRUE (12 < 13)shownNo
15FALSEnoneYes

The loop ends on 15, so the program only continues with an accepted value.

A length check follows the same shape. Here the password must have at least 8 characters:

REPEAT
  INPUT Password
  IF LENGTH(Password) < 8 THEN
    OUTPUT "At least 8 characters needed"
  ENDIF
UNTIL LENGTH(Password) >= 8

The mistake to watch for

Mistaken answer: “A range check makes sure the password is long enough.”

The student remembered the word “check” but not which property it tests.

Password length is a length check, because it counts characters. A range check compares a value with limits. Before naming a check, say aloud what is being tested: the size of a value, the number of characters, the data type, whether anything was entered, or the pattern.

Check yourself

1. A form says: “The exam score must be from 0 to 100.” Name the check.

Show answer

A range check, with lower limit 0 and upper limit 100.

2. A form says: “The email box must not be left blank.” Name the check, and say whether it proves the email is real.

Show answer

A presence check. It does not prove the email is real. It only proves that something was typed.

3. A student code must be exactly “CS” followed by three digits, such as CS417. Which check is this, and does CS999 pass?

Show answer

A format check. CS999 passes, because it follows the pattern, even if no student has that code. Validation checks the pattern, not the truth.

Where does this lead next?

The next lesson shows why verification is a different job from validation. Later you will design test data for a check like this one. You can step through a loop like the one above in the restricted pseudocode trace trainer, then try the mixed practice set.

If you still pick the wrong check under time pressure, a teacher in online one-to-one Computer Science tuition can give you new requirements to classify until the key words stand out.

Questions people ask

What is a validation check?

A validation check is an automatic test a program runs on data as it is entered, to decide whether the data is reasonable and allowed. If the data fails, the program rejects it and asks again. Validation cannot prove the data is the true value, only that it is acceptable.

How do I choose between a range check and a length check?

A range check looks at the size of a number or the position of a value between limits, such as an age from 13 to 17. A length check counts characters, such as a password with at least 8 characters. Ask yourself whether the requirement is about how big the value is or how many characters it has.

What is a format check?

A format check tests that data follows a set pattern, such as two letters followed by three digits like CS417. It checks the layout of the characters, not whether that code really exists. A presence check, by contrast, only tests that something was entered.

Do I write the check in pseudocode or Python?

Follow the question. Cambridge-style pseudocode is the safe default, and the pseudocode here uses the keywords IF, REPEAT, UNTIL and the LENGTH function. Python is fine for your own practice, but the logic of the check stays identical.

Updated:

Your next step

If you know the names of the checks but still pick the wrong one under time pressure, a one-to-one teacher can give you fresh requirements to classify and correct your reasoning on the spot.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parents: enquire here

  • 9,000+ students helped through our service
  • 9+ years helping IGCSE students