Validation and verification
<p>Learn about Validation and verification in this comprehensive lesson.</p>
Why This Matters
Imagine you're filling out a form online, like signing up for a new game or ordering your favourite pizza. Have you ever typed in your age, and it says, "Age must be between 5 and 99"? Or maybe you accidentally typed your phone number into the email address box? That's where **validation** and **verification** come in! These are super important computer science ideas that help make sure the information (or 'data') you put into a computer system is correct and makes sense. Without them, computer systems would be full of mistakes, and things wouldn't work properly, like trying to send an email to a phone number – it just wouldn't get there! So, let's dive in and see how computers act like helpful assistants, checking your work to keep everything running smoothly and accurately.
Key Words to Know
What Is This? (The Simple Version)
Think of it like a helpful friend checking your homework before you hand it in. They don't check if your answers are right (that's a different job!), but they check if your answers make sense and follow the rules.
Validation is like checking if the data you've entered is sensible and fits the rules. For example, if you're asked for your age, validation checks if you've entered a number that could actually be an age (like 15, not 'banana' or '5000'). It makes sure the data is in the correct format and within an acceptable range.
Verification is different. It's like double-checking that the data you've entered into the computer is exactly what you intended to enter. It's about making sure there are no accidental typos or mistakes when the data is being copied or moved. It's less about the 'rules' and more about 'did I type what I meant to type?'
Real-World Example
Let's imagine you're signing up for a new online game. You have to fill in a form:
- Username: You type 'CoolGamer123'. The system might use validation to check if the username is at least 6 characters long and doesn't contain any special symbols like '@' or '#'. If you typed 'Coo!' it would say 'Invalid username' because of the '!' symbol.
- Email Address: You type '[email protected]'. The system uses validation to check if it looks like a real email address (has an '@' and a '.' in the right places). If you typed 'myemailexamplecom', it would say 'Invalid email format'.
- Password: You type 'MySecretPass'. The system might use validation to check if it has uppercase letters, lowercase letters, and numbers.
- Confirm Password: You type 'MySecretPass' again. This is where verification comes in! The system checks if the 'Password' and 'Confirm Password' fields are exactly the same. If you typed 'MySecretPas' by mistake the second time, it would say 'Passwords do not match!', helping you catch your typo.
How Validation Works (Step by Step)
Validation is all about setting up rules for the computer to check your data.
- Define the Rules: Before anyone types anything, the programmer decides what kind of data is allowed. (e.g., 'Age must be a number between 1 and 120').
- User Enters Data: You type your information into a box on a form.
- Computer Checks Rules: The computer compares what you typed against the rules it was given.
- Accept or Reject: If your data follows all the rules, the computer accepts it. If it breaks a rule, the computer rejects it and usually shows an error message.
How Verification Works (Step by Step)
Verification is about making sure data is copied or entered accurately.
- Original Data: You have some data you want to enter, like a long product code.
- First Entry: You type the product code into the computer.
- Second Entry (or Check): You might be asked to type it again (like 'confirm password'), or the computer might use a special method to check it.
- Compare and Confirm: The computer compares the two entries. If they match, it's verified. If not, it asks you to try again.
Types of Validation Checks
Computers use different 'tests' to validate data, like a detective looking for clues.
- Range Check: Checks if a number is within a specific minimum and maximum value. (e.g., Age must be between 1 and 120).
- Type Check: Checks if the data is the correct type (e.g., Is it a number? Is it text? Is it a date?). If you need a number, but type 'hello', it fails.
- Length Check: Checks if the data has the correct number of characters. (e.g., A password must be at least 8 characters long).
- Format Check: Checks if the data follows a specific pattern. (e.g., A postcode like 'SW1A 0AA' or an email address like '[email protected]').
- Presence Check: Checks if a field hasn't been left empty. (e.g., You must enter your name; it can't be blank).
- Lookup Check: Checks if the data entered exists in a list of acceptable values. (e.g., Choosing 'UK' from a list of countries, rather than typing 'United Kingdom').
Common Mistakes (And How to Avoid Them)
It's easy to mix these up, but here's how to keep them straight!
-
Mistake 1: Thinking validation checks for 'truth'. ❌ You enter your age as '100', but you're only 12. Validation says 'OK' because 100 is a valid number for age. ✅ Remember, validation checks if the data makes sense and follows rules, not if it's actually true. It can't know your real age, only if '100' is a possible age. It's like your friend checking your homework for neatness, not if your maths answer is right.
-
Mistake 2: Confusing validation with verification. ❌ Thinking that re-typing your password (verification) is a type of validation. ✅ Validation is about the rules of the data itself (e.g., 'password must be 8 characters'). Verification is about accuracy during entry (e.g., 'did I type the same password twice?'). They are different jobs!
-
Mistake 3: Believing that validation makes data perfect. ❌ Assuming that once data passes validation, it's completely correct and error-free. ✅ Validation helps reduce errors, but it's not foolproof. For example, a range check might allow an age of '100' even if the person is 12. It simply means the data could be valid. Good systems use both validation and verification, plus human checks, for best results.
Exam Tips
- 1.Always define Validation and Verification separately in your answers, highlighting their distinct purposes.
- 2.When asked for types of validation, provide specific examples like 'range check' or 'format check' and explain what they do.
- 3.Remember that validation checks if data is *sensible* or *possible*, not if it's *true*.
- 4.For verification, focus on methods that confirm accuracy of entry, like double-entry or visual checks.
- 5.Practise identifying scenarios where validation would be used versus scenarios where verification would be used.