Knowledge Organiser: Input Validation
Key Terms
- Validation: Checking that data is acceptable and sensible before processing
- Range check: Ensures a value is within a minimum and maximum (e.g. age 0–120)
- Type check: Ensures data is the correct data type (e.g. integer, not text)
- Length check: Ensures data has the required number of characters
- Presence check: Ensures a required field is not left empty
- Format check: Ensures data matches an expected pattern (e.g. postcode format)
- Check digit: A calculated digit appended to data to detect errors (e.g. barcode)
Must-Know Facts
- Validation ensures data is sensible — it does NOT guarantee data is correct or accurate
- A user can enter a valid but wrong value (e.g. wrong age that still passes a range check)
- Validation ≠ Verification: verification checks data is what the user intended (e.g. entering twice)
- Multiple validation types can be applied to a single field
- Validation prevents programs from crashing due to unexpected input
Key Concepts
- Memory aid: RPTFL-C — Range, Presence, Type, Format, Length, Check digit
- Range check: if age >= 0 AND age <= 120 then accept endif
- Presence check: if email != "" then accept endif
- Length check: if password.length >= 8 then accept endif
Common Mistakes
- Saying validation guarantees data is correct: Validation only checks data is acceptable/sensible — a user can enter a valid but wrong value (e.g. wrong date of birth that passes a range check)
- Confusing validation with verification: Validation checks data meets rules; verification checks data matches what the user intended (e.g. typing a password twice to confirm)
- Applying the wrong validation type to a scenario: A postcode needs a format check (pattern); an age field needs a range check (min/max) — match the check to the data type
- Forgetting the presence check: Presence check is a separate type — leaving a required field empty should trigger it, not a range or type check
- Describing validation as "stopping hackers": Validation primarily prevents program crashes from unexpected input; sanitisation (not validation) specifically prevents injection attacks