Chevron Left Icon
Introduction to Form Validation
Lesson 1 of 3
Chevron Right Icon
  1. 1
    Modern websites require a lot of information to function as intended. Information like our usernames, passwords, “friends”, “likes”, credit card information, and shopping orders all have to be prov…
  2. 2
    Most data, once submitted, is stored by a website or web application. It’s stored in a database on the server side. There are important reasons for us to make sure the information that will be stor…
  3. 3
    Data submitted through forms are stored as strings. Strings are a fundamental data type in computer science representing a series of characters “strung” together. As humans, we can intuitively reco…
  4. 4
    The first technique we can use to validate form data is to prevent problematic inputs from being submitted in the first place. This is called client-side validation. The client is the process int…
  5. 5
    Client-side validation has two main advantages. First, it’s a better experience for the user to be alerted to problematic data immediately rather than having to wait for that information to come ba…
  6. 6
    No matter how complete the front-end validation of a website or application seems, validations must also be completed on the back-end or server-side. Front-end validations are easy to bypass—a mali…
  7. 7
    In this lesson, we’ve explored form validation from many angles. Let’s review what we covered: + Modern websites require a lot of information from their users and they collect a lot of this informa…
  1. 1
    When registering an account for a new social media app or completing an order for a gift online, nearly every piece of information you enter into a web form is validated. Did you enter a properly f…
  2. 2
    The simplest text we can match with regular expressions are literals. This is where our regular expression contains the exact text that we want to match. The regex a, for example, will match …
  3. 3
    Do you love baboons and gorillas? You can find either of them with the same regular expression using alternation! Alternation, performed in regular expressions with the pipe symbol, |, allows…
  4. 4
    Spelling tests may seem like a distant memory from grade school, but we ultimately take them every day while typing. It’s easy to make mistakes on commonly misspelled words like consensus, and on t…
  5. 5
    Sometimes we don’t care exactly WHAT characters are in a text, just that there are SOME characters. Enter the wildcard .! Wildcards will match any single character (letter, number, symbol or …
  6. 6
    Character sets are great, but their true power isn’t realized without ranges. Ranges allow us to specify a range of characters in which we can make a match without having to type out each ind…
  7. 7
    While character ranges are extremely useful, they can be cumbersome to write out every single time you want to match common ranges such as those that designate alphabetical characters or digits. To…
  8. 8
    Remember when we were in love with baboons and gorillas a few exercises ago? We were able to match either baboons or gorillas using the regex baboons|gorillas, taking advantage of the | symbol. Bu…
  9. 9
    Here’s where things start to get really interesting. So far we have only matched text on a character by character basis. But instead of writing the regex \w\w\w\w\w\w\s\w\w\w\w\w\w, which would mat…
  10. 10
    You are working on a research project that summarizes the findings of primate behavioral scientists from around the world. Of particular interest to you are the scientists’ observations of humor in…
  11. 11
    In 1951, mathematician Stephen Cole Kleene developed a system to match patterns in written language with mathematical notation. This notation is now known as regular expressions! In his honor, the…
  12. 12
    When writing regular expressions, it’s useful to make the expression as specific as possible in order to ensure that we do not match unintended text. To aid in this mission of specificity, we can u…
  13. 13
    Do you feel those regular expression superpowers coursing through your body? Do you just want to scream ah+ really loud? Awesome! You are now ready to take these skills and use them out in the wild…
  1. 1
    In this lesson, we’ll be using PHP to handle user input submitted through HTML forms. We’ll be performing form validations on the submitted data in order to protect our website and its users. …
  2. 2
    Throughout this lesson, we’ll be using a PHP file to present an HTML form to users. We’ll be using the POST method attribute for more secure input submission. This means all the data submitted wi…
  3. 3
    In the previous exercise, we simply displayed the user input we received. Now we want to provide the user with feedback if their input isn’t correct. We’ll validate (confirm the correctness of) t…
  4. 4
    In the previous exercise, we performed a simple validation to check the user’s input, but we made a mistake by directly displaying the data we received from them. Remember that we must never simply…
  5. 5
    We haven’t yet introduced the most powerful PHP function for sanitizing data: filter_var(). This function operates on a variable and passes …
  6. 6
    We can use the same filter_var() function to validate as well as sanitize! There are a number of provided validation filters, but th…
  7. 7
    The filter_var() function accepts an optional third argument that allows us to fine-tune the operation of a given filter. This argument, often called $options, takes the form of a nested associativ…
  8. 8
    We’ll often find the validations offered by built-in functions like filter_var() to be insufficient. When validating all but the simplest data, we’ll likely need to write our own, custom input vali…
  9. 9
    Because modern websites and web applications need to store a lot of data, they usually interact with databases on the back-end. A common type of custom validation involves comparing user input agai…
  10. 10
    In addition to sanitizing data that is displayed to the user, we always need to sanitize all data before storing it in our own databases. There are serious security concerns with storing data in a …
  11. 11
    In this lesson, we’ve learned some basic tools to validate HTML forms on the back-end using PHP. We learned how to send meaningful feedback to our users when their inputs are invalid. But what shou…
  12. 12
    Great work! We covered a lot in this lesson. Let’s review: + Performing back-end form validations on the data submitted is an essential step to protect our website and its users. + Using the POST…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo