17.1 What is Validation?
Validation is the process of checking that data entered is REASONABLE and MEETS CRITERIA before it is stored or processed. It is performed at INPUT time — the program checks the value immediately and either accepts or rejects it.
- Performed at input time — the check runs as the data is entered.
- Checks reasonableness — does the data meet the defined rules?
- Does NOT check correctness — a valid age (e.g. 25) may still be the wrong age for the person.
- Five common types — Range, Length, Type, Presence, Format.
Key idea: validation asks "Is the data reasonable?" — it does NOT ask "Is the data true?". A range check on Age 0–120 accepts 25, even if the user is actually 47. Correctness is the job of verification.
Common mistake: thinking validation guarantees correctness. It only guarantees reasonableness. To check correctness, you need verification (e.g. double entry or visual check).
Concepts — What is Validation?
17.2 Range Check
A range check verifies that an input value falls within a specified lower and upper bound. It is typically used for numeric data such as age, exam score, temperature, or quantity.
DECLARE Age : INTEGER
OUTPUT "Enter age: "
INPUT Age
IF Age >= 0 AND Age <= 120 THEN
OUTPUT "Valid age"
ELSE
OUTPUT "Invalid age"
ENDIF- Inclusive bounds —
>=and<=accept values AT the boundary. - Two conditions joined with AND — both must be true for the value to pass.
- Typical uses — age 0–120, exam score 0–100, month 1–12, day 1–31.
- Rejects — out-of-range values such as Age = 150 or Score = -5.
Exam tip: if a question says "value must be between X and Y", that is a range check. Use IF Value >= X AND Value <= Y THEN ... ELSE ... ENDIF. Do not forget to handle the boundary values correctly.
Range Check — Values Within Bounds
17.3 Length Check
A length check verifies that a string input has the correct number of characters. The rule can be a minimum length, a maximum length, or an exact length. It uses the built-in LENGTH() function.
DECLARE Password : STRING
OUTPUT "Enter password: "
INPUT Password
IF LENGTH(Password) >= 8 THEN
OUTPUT "Valid password"
ELSE
OUTPUT "Password too short"
ENDIF- Minimum length —
LENGTH(Pwd) >= 8. - Maximum length —
LENGTH(Tweet) <= 280. - Exact length —
LENGTH(Phone) = 11. - Uses LENGTH() built-in — returns the character count as an INTEGER.
Watch out: a length check does NOT guarantee strength or quality. A password of "aaaaaaaa" passes LENGTH >= 8 but is very weak. Strength also depends on character variety — uppercase, digits, symbols.
Exam tip: the LENGTH() function returns an INTEGER, so you can compare it directly with >=, <=, =, <>. Always use LENGTH() — never count characters manually.
Length Check — Correct Number of Characters
17.4 Type Check and Presence Check
A type check verifies that the input is of the correct data type (e.g. INTEGER, REAL, STRING, BOOLEAN). A presence check verifies that a field is not empty — i.e. the user has supplied a value.
- Type check — input must match the declared data type. Declaring
Age : INTEGERand usingINPUT Agerejects non-numeric input. - Presence check — input must not be empty. Test with
IF Name = "" THEN. - Used together — a name field needs both a presence check (not empty) AND a type check (must be STRING).
DECLARE Name : STRING
OUTPUT "Enter name: "
INPUT Name
IF Name = "" THEN
OUTPUT "Name is required"
ELSE
OUTPUT "Valid name"
ENDIFThe above example performs a presence check on the Name field. If the user presses Enter without typing anything, Name becomes the empty string "" and the check fails with "Name is required".
How type checks work in CIE pseudocode: when a variable is declared as INTEGER and the user enters text like "twenty", the INPUT statement fails because text cannot be stored as an integer. The declared type acts as an implicit type check.
Type & Presence Checks — Right Type, Not Empty
17.5 What is Verification?
Verification is the process of checking that data has been ACCURATELY COPIED or ENTERED. It is performed AFTER data entry — not at input time. The two main methods are double entry and visual check (proofreading).
- Double entry — user enters the same data twice; system compares the two entries.
- Visual check — user proofreads the entered data against the source.
- Performed AFTER input — not at the moment of entry.
- Catches transcription errors — e.g. typing 25 instead of 52.
DECLARE Email1, Email2 : STRING
OUTPUT "Enter email: "
INPUT Email1
OUTPUT "Confirm email: "
INPUT Email2
IF Email1 = Email2 THEN
OUTPUT "Email verified"
ELSE
OUTPUT "Emails do not match - re-enter"
ENDIFThis is double-entry verification. The user enters the email address twice. If the two entries match, the data is verified. If they differ, the user must re-enter — the mismatch suggests a typing error.
| Aspect | Validation | Verification |
|---|---|---|
| Question | Is the data reasonable? | Was the data entered correctly? |
| When | At INPUT time | AFTER input |
| Methods | Range, Length, Type, Presence, Format | Double entry, Visual check |
| Catches | Unreasonable values (age 999) | Transcription errors (52 vs 25) |
Key idea: validation and verification are COMPLEMENTARY. Validation rejects obviously bad input (age 999). Verification catches typing slips (entering 25 instead of 52 for an account number). You need both for clean data.
Verification — Accurately Entered Data
17.6 Key Points Summary
A quick recap of everything covered on validation and verification:
- Validation = reasonable — Checks data entered is reasonable and meets criteria.
- Verification = accurately entered — Checks data has been accurately copied or entered.
- Validation at INPUT time — Performed as data is entered — immediate accept/reject.
- Verification AFTER input — Performed after entry — comparison or proofread.
- Five validation types — Range, Length, Type, Presence, Format.
- Two verification methods — Double entry (enter twice, compare), Visual check (proofread).
- Range check — IF Value >= Min AND Value <= Max THEN ... — inclusive bounds.
- Length check — IF LENGTH(Str) >= N THEN ... — uses the LENGTH() built-in.
- Type check — Declared data type acts as implicit type check during INPUT.
- Presence check — IF Field = "" THEN reject — field must not be empty.
- Validation ≠ correctness — A valid value (age 25) may still be wrong for the person.
- Both needed — Validation + verification together give the best data integrity.
Exam tip: in an exam, always state WHICH type of validation is being used (range, length, type, presence, or format) and explain WHY. For verification questions, name the method (double entry OR visual check) and describe how it works.