ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Robust programs/Presence, length, type and format checks
J277 · 2.3.1

Unit 10 · Lesson 3

Presence, length, type and format checks

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Describe common validation types and implement presence, length and simple format checks with loops.

Different inputs need different validation. A presence check rejects a blank string. A length check measures characters. A type check asks whether the data has the required type, while a format check examines its pattern, such as DD/MM/YYYY. A look-up check compares input with known allowed values. More than one rule may be needed, and a loop repeats until all required checks pass.

Presence check

A validation check that ensures data has been entered and is not blank.

Length check

A validation check that ensures input has the required number of characters.

Type check

A validation check that ensures data has the required data type.

Format check

A validation check that ensures data follows a required pattern or structure.

Look-up check

A validation check that compares input with a predefined list of allowed values.

Keep these in mind

  • Presence means the input is not an empty string.
  • Length checks use .length in ERL and len() in Python.
  • A type check concerns the kind of data, not whether its value is true.
  • Casting with int() is not itself a type check: unsuitable text causes a runtime error unless the program validates or safely handles it.
  • A format check tests a pattern, such as a separator in a fixed position.
  • A look-up check compares against a predefined allowed collection.
  • All required validations must pass before input is accepted.

Learning objective

Describe common validation types and implement presence, length and simple format checks with loops.

Exam tip

Name the validation type and explain how it applies, such as 'length check—ensure the code contains exactly five characters'.

Common mistake

Validation checks reasonableness and structure, not factual correctness. A correctly formatted date can still describe the wrong real-world event.

PreviousNext