Validation + Verification cards :)

Validation checks include:

Length check:

#Length check
while len(checkVal) > 15:
    checkVal = input("Please enter a smaller value")
    # a length check can be testing whether its smaller or larger
    # than what is needed

Presence check:

checkVal = input("Please enter a value")

#Presence check
while checkVal == "":
    checkVal = input("You entered nothing, please try again")
                      #"" means its nothing - you can't write "  ",
                      # as the code will check for space

Type check: not on spec!!

Type check can be immediately done with casting. Default is a string, but can be changed using number = int(input) or number = bool(input), etc

#Type check
day = date[0:2] #this only 'goes up to' the last digit - 2 and 5
month = [3:5]   # are not included
year = [6:]     # by leaving the last digit blank, this just means
                # 'everything after' the 6th digit

if day.isnumeric() and month.isnumeric() and year.isnumeric():
    print("That is a valid date")

Format check:

#Format check:
date = input("Enter a date (e.g. DD/MM/YYYY)")
#the value position are:         0123456789
if date =[2] != "/" or date[5] != "/":
    print("You forgot your slashes or they are in the wrong position")
    
email = "madeupemail@wghs.org.uk" #think of when you enter an email, and
flag = False                      #the enter button is red until you
for i in range(len(email)):       #enter "@" - this is that check
    if email[i] == "@":
        flag = True

Range check:

#Range check
if checkVal >= 10 and checkVal <= 50:
    print("That is within range")
    
while checkVal < 10 or checkVal >50:
    checkVal = input("Your entry is out of range, try again.")

Basic Validation checks:

  • Presence check

  • Length check

  • Range check

  • Format check

  • Type check

Validation checks the data entry is reasonable but cannot assure it is accurate


What?

Why?

Where?

Presence check

a data value must be entered.

For example, entering a quantity when placing an order.

Length check

the input must not be too long or too short. a data value must be entered.

A username will need to be between a certain amount of characters- usually 8 to 40

Range check

the input must fall within a specified range. This is usually applied to numbers and dates, but can apply to characters.

Making a payment - must be above 0, but less than available funds

Format check

the data must be in the correct format

entering a date in the format DD/MM/YYYY.

Type check

the data must be of a specified data type

ensuring input is an integer when specifying a quantity.


Verification !!

Verification attempts to ensure the data entry is accurate

  • usually done by a double entry to make sure they’re both the same

  • For example, this could be retyping an email or new password.

  • This is often used when verifying a new email-based account - this then goes to authentification

Authentication

Methods to confirm the identity of a user

This could be when:

  • a user ID

  • password

  • face ID

  • fingerprints

Input sanitisation

Sanitising an input “cleans” it so that it does not contain anything malicious, whether intentional or not.

For example:

  • sanitising SQL entry to prevent SQL injection

  • Removing invalid characters not allowed in passwords/usernames

Maintainability

Enabling the future use of your program - everyone can understand it

This makes it easier for future programmers (including yourself) to identify and fix problems

Making it easier to extend the original program if clients have extra/ specific requirements

It includes avoiding things like:

  • no comments

  • too many comments

  • inconsistent/ no idents

  • repeating code > loops

  • one letter variable names

Use comments to:

  • explain the purpose

  • explain sections of code

  • explain unusual approaches

  • Divide sections of code

Use indentation for every selection and iteration branch

Use descriptive variable names using naming conventions

  • Explain the purpose with a comment when declared

  • Constant declared at top of a program

Use sub-routines to:

  • Structure code to

  • Eliminate duplicating code

  • Make it easier/ faster to reuse code