Introduction to Validation

or

The art of not trusting anything from your visitors

Objectives

  • Describe what validation is
  • Describe why validation is important
  • Describe where data should be validated
  • Use regex to validate form data
  • Validate uniqueness of data

What is validation?

A QA engineer walks into a bar

He orders

  • 1 beer
  • 10 beers
  • 0 beers
  • an elephant

Why validation?

Your users will do stupid things on purpose or by accident

Where should validation go?

Hint, never trust anything that the visitor touches

Check for Understanding

Cold call

What is validation?

Check for Understanding

Cold call

Why do we need validation?

Check for Understanding

Taking hands

Why should you validate on the server?

What is regex?

You have a problem

 

You use regex to solve the problem

 

You now have two problems

How to create a regular expression

  • By hand
  • new RegExp
  • match

You do

In your REPL...

var str = '45abcACED&%';

// Create a regular expression that will filter 
// out all numbers so that you only have letters

Check for Understanding

Whiteboards

Write down a regular expression

Exercise

Create an express server with a form that has backend validation

https://github.com/gSchool/express-drills/tree/master/contact-validations

validating user input (backend)

By Brooks Patton

validating user input (backend)

Validating user input with express and node

  • 1,063