Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Python Validation Exercises

For each of the challenges below you need to create a function that validates input against the criteria

Rules

● You must comment the type (or types) of validation that is occurring in the function.
● Each function will take one (or more) parameter
● Each function will return True or False depending on whether tests are passed/failed

--------------------------------------------------------------------------------------------------------------------------------------------------
-

Exercise 1 - City Name

● The string must not be empty

Exercise 2 - Social Media Age Check

● The age must be a positive integer between 13 and 120 (inclusive).

Exercise 3 - Birth Year

● The year must be between 1900 and the current year(use the datetime module)

Exercise 4 - Day of Week

● Must be a valid day of the week, e.g. 'Monday'

Exercise 5 - First Name Check

● The name must contain only letters,numbers, spaces or a hyphen '-'

Exercise 6 - Max passengers

● Must be a valid positive integer (not a real/float)


● This function takes 2 arguments, the first is the maximum allowed number of passengers for a vehicle.

Exercise 7 - Date of Birth

● The date must be a valid date in the DD/MM/YYYY format


Exercise 8 - Even Parity Checker

● The input parameter should be an 8 digit binary number


● The input parameter should have even parity

Exercise 9 - Password Complexity Checker

● Must be between 8 and 32 characters


● Must have a minimum of 1 letter, 1 number, 1 symbol, no spaces, 1 upper case, 1 lower case
● Must not contain any of the following: password, god, 12345,letmein,secret,mellon

Exercise 10 (Optional) - Postcode Checker

● Valid format:
● [2 letters] [1 or 2 Digits] [Space] [1 Digit] [2 letters]
● (This is a slight simplification from the real UK postcode system to make the challenge a little easier)
● Hint: You might want to use the .partition string method.

Exercise 11 (Optional) - Check Valid Email Address

● Must contain at least 1 character before the at symbol


● Must contain an @ symbol
● Must have at-least 1 character after the @ symbol
● and before the period(.)
● Must contain at least 1 character after the last period(.).
● Maximum 256 characters

You might also like