Input Validation
Input Validation
Ensure that the data which the user has entered is within a
reasonable range
Program should repeatedly ask the user to re-enter until acceptable
data has been entered
Example:
A program ask the user to enter a month of the year in numeric
form
Acceptable data entries are 1,2,3,4,5,6,7,8,8,10,11,12
If the user enters any other data they should be asked to re-enter
Input Validation
Input Validation
What are the acceptable data ranges for the following:
Input Valid Entries
Day of the week in numeric form
A person’s age
A person’s sex
A lottery number
A pupil’s year group
A pupil’s tutor group
Input Validation
What are the acceptable data ranges for the following:
Input Valid Entries
Day of the week in numeric form 1 – 7
A person’s age 0 – 115
A person’s sex m, f, male, female
A lottery number 1 – 49
A pupil’s year group 1 – 6
A pupil’s tutor group Various solutions…
Input Validation
Input validation works well with simple numeric data, but what
about more complex entries?
Bank account number – program could check the correct
number of digits, and that all characters are numeric
Person’s name – program could ask the user if the entry is
correct (Y/N)
Where possible, programs can reduce errors by restricting
options using drop-down menu. But will this still be correct?
Pseudocode
The basic input validation pseudocode takes the following
form
Pseudocode – Exam Score
A program should ask the user to enter their exam score
Acceptable scores are 0-100
Code – Exam Score
A program should ask the user to enter their exam score
Acceptable scores are 0-100
Pseudocode – Multiple choice
A program should ask the user to enter the answer to a
multiple choice question: 1, 2 or 3
Pseudocode – Multiple choice
A program should ask the user to enter the answer to a
multiple choice question: 1, 2 or 3
Code – Multiple Choice
A program should ask the user to enter the answer to a
multiple choice question: 1, 2 or 3

SD & D Input Validation

  • 1.
  • 2.
    Input Validation Ensure thatthe data which the user has entered is within a reasonable range Program should repeatedly ask the user to re-enter until acceptable data has been entered Example: A program ask the user to enter a month of the year in numeric form Acceptable data entries are 1,2,3,4,5,6,7,8,8,10,11,12 If the user enters any other data they should be asked to re-enter
  • 3.
  • 4.
    Input Validation What arethe acceptable data ranges for the following: Input Valid Entries Day of the week in numeric form A person’s age A person’s sex A lottery number A pupil’s year group A pupil’s tutor group
  • 5.
    Input Validation What arethe acceptable data ranges for the following: Input Valid Entries Day of the week in numeric form 1 – 7 A person’s age 0 – 115 A person’s sex m, f, male, female A lottery number 1 – 49 A pupil’s year group 1 – 6 A pupil’s tutor group Various solutions…
  • 6.
    Input Validation Input validationworks well with simple numeric data, but what about more complex entries? Bank account number – program could check the correct number of digits, and that all characters are numeric Person’s name – program could ask the user if the entry is correct (Y/N) Where possible, programs can reduce errors by restricting options using drop-down menu. But will this still be correct?
  • 7.
    Pseudocode The basic inputvalidation pseudocode takes the following form
  • 8.
    Pseudocode – ExamScore A program should ask the user to enter their exam score Acceptable scores are 0-100
  • 9.
    Code – ExamScore A program should ask the user to enter their exam score Acceptable scores are 0-100
  • 10.
    Pseudocode – Multiplechoice A program should ask the user to enter the answer to a multiple choice question: 1, 2 or 3
  • 11.
    Pseudocode – Multiplechoice A program should ask the user to enter the answer to a multiple choice question: 1, 2 or 3
  • 12.
    Code – MultipleChoice A program should ask the user to enter the answer to a multiple choice question: 1, 2 or 3