Photo AI

Last Updated Sep 26, 2025

Input Validation Simplified Revision Notes

Revision notes with simplified explanations to understand Input Validation quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

356+ students studying

Input Validation

Input validation is the process of ensuring that the data entered into a system is sensible, reasonable, and meets certain predefined criteria. This helps prevent errors and protects against malicious data that could harm the system or cause it to behave unexpectedly.

Input Validation vs Input Sanitisation

Input ValidationInput Sanitisation
Ensures the data is sensible and meets specific criteria but doesn't check for accuracy.Cleans data to remove any unwanted or harmful characters before it is processed.
Checks things like length, format, and range.May remove or escape harmful characters, spaces, or symbols from user input to prevent attacks like SQL injection.
For example, checks if a password is at least 8 characters long.For example, removes special symbols from a text field to prevent malicious code entry.

Types of Validation Checks

Validation CheckDescriptionExample
Check digitThe last digit(s) in a number is used to verify that the other digits are correct.Bar code readers use check digits to verify product codes.
Format checkEnsures data follows a specific format.For example, a date must follow the format DD/MM/YYYY.
Length checkChecks that the input data is of the correct length.A password must be exactly 8 characters long.
Lookup tableChecks that data matches one of the valid values from a predefined list.For example, gender could be limited to options in a dropdown menu.
Presence checkEnsures that data is entered into a required field.A form field for "Name" must not be left empty.
Range checkEnsures that a value falls within a specified range.A person's age must be between 0 and 120.

Designing Input Validation in Practice

When designing a system that requires input validation, it's important to implement several checks to ensure that users cannot enter invalid or harmful data. For example:

Username Validation

  • Use a length check to ensure the username is not too short or long.
  • Use a format check to ensure only valid characters (letters and numbers) are used.

Example in Python:

username = input("Enter username: ")
if len(username) < 5 or len(username) > 15:
    print("Username must be between 5 and 15 characters.")
elif not username.isalnum():
    print("Username can only contain letters and numbers.")

Password Validation

Use a length check to ensure the password is at least 8 characters long.

Use a format check to require a mix of upper and lowercase letters, numbers, and special characters.

Example in Python:

password = input("Enter password: ")
if len(password) < 8:
    print("Password must be at least 8 characters.")
elif not any(char.isdigit() for char in password):
    print("Password must contain at least one number.")
elif not any(char.isupper() for char in password):
    print("Password must contain at least one uppercase letter.")

Simple Authentication System (Username and Password)

A simple authentication system can be created by combining input validation for both the username and password fields. This system verifies that the user input matches predefined valid credentials.

Example of Simple Authentication in Python

# Predefined username and password
correct_username = "user123"
correct_password = "Password123!"

# Ask for input from the user
username = input("Enter username: ")
password = input("Enter password: ")

# Validate username and password
if username == correct_username and password == correct_password:
    print("Access Granted")
else:
    print("Invalid username or password")

In this example, the program validates the input by checking if the entered username and password match the correct predefined values. If both are correct, access is granted.

infoNote

Key Points to Remember

  • Input validation helps ensure data is sensible, meets criteria, and prevents errors or security issues.
  • Types of validation checks include presence, length, format, range, and lookup checks.
  • Designing validation for simple authentication involves checking the username and password for format, length, and validity before granting access.
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Input Validation

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

70 flashcards

Flashcards on Input Validation

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

7 quizzes

Quizzes on Input Validation

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

6 questions

Exam questions on Input Validation

Boost your confidence with real exam questions.

Try Computer Science Questions

27 exams created

Exam Builder on Input Validation

Create custom exams across topics for better practice!

Try Computer Science exam builder

13 papers

Past Papers on Input Validation

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Input Validation you should explore

Discover More Revision Notes Related to Input Validation to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Defensive Design & Testing

Defensive Design Considerations

user avatar
user avatar
user avatar
user avatar
user avatar

211+ studying

188KViews

96%

114 rated

Defensive Design & Testing

Program Maintainability

user avatar
user avatar
user avatar
user avatar
user avatar

434+ studying

181KViews

96%

114 rated

Defensive Design & Testing

Testing Programs

user avatar
user avatar
user avatar
user avatar
user avatar

405+ studying

186KViews

96%

114 rated

Defensive Design & Testing

Identify Syntax & Logic Errors in Testing

user avatar
user avatar
user avatar
user avatar
user avatar

477+ studying

191KViews
Load more notes

Join 500,000+ GCSE students using SimpleStudy...

Join Thousands of GCSE Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered