Computer Science GCES OCR
-
Cpu Architecture Performance And Embedded Systems Ocr5 主题
-
Primary And Secondary Storage Ocr6 主题
-
Data Storage And Compression Ocr12 主题
-
Units Of Data Storage Ocr
-
Processing Binary Data Ocr
-
Data Capacity And Calculating Capacity Requirements Ocr
-
Converting Between Denary And Binary Ocr
-
Binary Addition Ocr
-
Converting Between Denary And Hexadecimal Ocr
-
Converting Between Binary And Hexadecimal Ocr
-
Binary Shifts Ocr
-
Representing Characters Ocr
-
Representing Images Ocr
-
Representing Sound Ocr
-
Compression Ocr
-
Units Of Data Storage Ocr
-
Networks And Topologies Ocr6 主题
-
Wired And Wireless Networks Protocols And Layers Ocr6 主题
-
Identifying And Preventing Threats To Computer Systems And Networks Ocr2 主题
-
Operating Systems And Utility Software Ocr2 主题
-
Ethical Legal Cultural And Environmental Impact Ocr2 主题
-
Computational Thinking Searching And Sorting Algorithms Ocr3 主题
-
Designing Creating And Refining Algorithms Ocr5 主题
-
Programming Fundamentals And Data Types Ocr5 主题
-
Additional Programming Techniques Ocr7 主题
-
Defensive Design And Testing Ocr6 主题
-
Boolean Logic Diagrams Ocr2 主题
-
Programming Languages And Integrated Development Environments Ides Ocr3 主题
-
The Exam Papers Ocr2 主题
-
Structuring Your Responses Ocr3 主题
Input Validation Ocr
Exam code:J277
Input Validation
What is Input Validation?
-
Input validation is code which is used to check that an input from a user is acceptable and that it matches the requirements of the program
-
There are 5 main categories of validation which can be carried out on fields and data types, these are
-
Length check
-
Type check
-
Range check
-
Presence check
-
Format check
-
-
There can be occasions where more than one type of validation will be used on a field
-
An example of this could be a password field which could have a length, presence and type check on it

Length check
-
Checks the length of a string
-
An example is ensuring that a password is 8 or more characters in length
-
Code example
|
|
Type check
-
Check the data type of a field
-
An example is checking a user’s age has been entered as an integer, without creating an integer input
-
Code example
|
|
Range check
-
Ensures the data entered as a number falls within a particular range
-
An example is checking a user’s age has been entered and falls between the digits of 0-100
-
Code example
|
|
Presence check
-
Looks to see if any data has been entered in a field
-
An example is checking that a user has entered a name when registering for a website
-
Code example
|
|
Format check
-
Ensures that the data has been entered in the correct format
-
An example would be ensuring that an email includes the @ symbol and a full stop (.)
-
Code example
|
|
Worked Example
A car dealership uses a computer system to record details of the cars that it has for sale. Each car has a make, model, age and number of miles driven.
The car dealership only sells cars that have fewer than 15,000 miles and are 10 years old or less.
Write an algorithm that will:
-
Ask the user to enter the number of miles and the age of a car
-
Validate the input to check that only sensible values that are in the given range are entered
-
Output True if valid data has been entered or False if invalid data has been entered [4]
How to answer this question
-
When answering any algorithm question, ask yourself:
-
What inputs and outputs do I need?
-
Do I need to do any calculations or comparisons?
-
Do I need to use selection or iteration?
-
Do I need to use a function or procedure?
-
-
Re-read the algorithm question working through the criteria given
|
Programming Skill |
Algorithm |
|---|---|
|
Inputs |
|
|
Outputs |
|
|
Calculations / Comparisons |
|
|
Selection or Iteration |
|
|
Function or Procedure |
|
Answer:
i)1 mark per bullet, max 4
-
Miles and age input separately
-
Checks for valid mileage
-
Checks for valid age
-
Checks both are greater than / greater than equal to zero
-
…correctly outputs both True and False
Example Answer:
miles = int(input("enter miles driven"))age = int(input("enter age of car"))valid = Trueif miles > 15000 or miles < 0 then valid = Falseelif age > 10 or age < 0 then valid = Falseendifprint(valid)
Responses