Adding validation to our project
Now that we've done the theory, why not see if you can add some validation to our MongoosePM application? We're not going to walk through this here, but do try it out yourself. If you're impatient you can of course just download the source code from Packt's website. The code contains various ways of achieving the same validation, commented out for reference.
For users, try adding the following validations:
Name: Make this
required
, and with a minimum length of five charactersEmail: Make this
required
, unique, and only allow a valid e-mail addressTip
Use a regular expression.
For projects, have a go at this:
projectName: Make this
required
, with a minimum length of five characters, and only accept unique values for each userTip
Use an asynchronous validator.
To get the validation working for both users and projects, you will need to:
Update the schemas to include validators
Update the create/edit controllers to interpret the error messages
Save the submitted data...