大象传媒

Sorting, searching and validation - EduqasData validation and verification

Sorting and searching are two of the most frequently needed tasks in program design. Common algorithms have evolved to take account of this need, such as linear search, binary search, bubble sort and merge sort.

Part of Computer ScienceUnderstanding Computer Science

Data validation and verification

Data validation

A programmer should consider that any a user makes might be incorrect and should plan arrangements for such unexpected actions. Using helps a programmer to ensure that any input is possible and sensible.

Validation applies rules to input data. If the data does not follow the rules it is rejected, reducing the risk that incorrectly input data may crash a program.

A programmer can build various types of validation into a program:

  • Range check - the input must fall within a specified range. This is usually applied to numbers and dates but can apply to characters. For example, when making a payment to someone, the amount to be entered might be set to be greater than zero and not greater than the funds available.
  • Length check - the input must not be too long or too short. For example, a surname will require at least one letter but is unlikely to require more than 40.
  • Presence check - a data value must be entered. For example, entering a quantity when placing an order.
  • Format check - the data must be in the correct format, such as entering a date in the format DD/MM/YYYY.
  • Type check - the data must be of a specified , such as an when specifying a quantity.
  • Lookup table - this allows the user to pick one item from a specified pre-defined list.
  • Check digit - often used on identification numbers, such as bank account numbers, to ensure the numbers have been entered correctly.

Many programs use one or more of these validation checks. For example, when signing up for a user account on a website, the validation might include:

  • presence check - a username must be entered
  • length check - a password must be at least eight characters long
  • range check - age restrictions may require the user's date of birth to be before a certain date
  • format check - the user's date of birth must be entered in the specified format
  • type check - the password may need to have a mixture of upper- and lower-case letters, a number and a special character
  • look up check - the title must be from a pre-defined list of valid entries

Validation can be very simple. This program will iterate until the user enters a correct response.

response is string
                    set response = ""
                    while response <> "a" AND response <> "b"
                        input "Which option do you prefer? a/b", 
                    	response
                    end while
                    output "Okay, let's continue..."

Verification

Validation does not ensure that the data entered is correct, just that it is possible and sensible. A user may accidentally enter a date of birth that is possible and sensible, but incorrect. The program has no way of knowing that the date has been entered incorrectly.

To check if the data entered is correct, verification is needed. Take, for example, a customer鈥檚 email address. A company wants to make sure they get this correct so they might use data verification to ensure it is entered correctly.

There are two main methods of verification:

  • Double keying - entering the data twice and comparing the two copies.
  • Proofreading data - this involves someone checking the data entered against an original document. This is time-consuming and costly and is mainly used only for very important information such as the checking of ID.

To find out more, see the Internet and cybersecurity study guide.