Validation Practice

  1. Modify one of your programs that requires the input of an integer to validate it before use.

  2. Write a program that will validate a real number. You could use the program ValidateInteger to help you.

  3. Write a program that will validate the format of a date to be dd/mm/yyyy where d, m and y are digits.

  4. Validate a UK postcode. You will need the following information for this challenging task.

    Each postcode consists of two parts separated by a space. The first part is the outcode, which identifies the area and district. The second part is the incode, which is used to sort the mail at the local area delivery office.

    The following is a list of the valid formats of postcode. An ‘A’ indicates an alphabetic character and a ‘D’ indicates a digit.

         Format         Example 
    Outcode   Incode    Postcode 
    AD        DAA       S1 1WB
    ADD       DAA       S10 2HB
    AAD       DAA       WD3 3AQ
    AADD      DAA       WD18 7JF
    ADA       DAA       W1A 1AB
    AADA      DAA       WC1E 6DB

    The characters C, I, K, M, O and V are never used in the incode.

    You could start by writing and testing a function to validate a single common format such as AAD DAA.

  5. A new book is issued with a GTIN-13 code, also known as ISBN 13. Write a program with a function that will calculate the check digit from the other 12 digits of a GTIN-13 code number. The weights of the digits are tabulated below.

    Digit position 1 2 3 4 5 6 7 8 9 10 11 12 13
    Weight (multiplier) 1 3 1 3 1 3 1 3 1 3 1 3  
  6. Include another function that will validate a GTIN-13 code.

Programming - a skill for life!

Checking data to see if it is sensible