In this section we’re finally going to talk about validating forms. This is a really important piece of creating a fully functional form. Validation helps you to get better information from the user and it also gives them a way to know why their input is invalid which creates a better user experience. When we validate forms, it means that we can specify what is valid input from the user. For example, we could specify that a user can’t entire a bunch of exclamation points in their name.
In a reactive form, validation logic is done in the component. We’ll add validator functions to the form model which will be synced every time the control is changed.
For this course I’m going to focus on synchronous validators, but async validators can be used when you want to validate against a database or api. For instance, if you want to check that if you can take a certain username was free, an app could asynchronously validate that to the database, then return the status once the call is complete. All great things to dive deeper into on your own or in a future course!
What we will cover in this section includes: 1. Built-in validators 2. Displaying error messages 3. Updating validators dynamically 4. Custom validators 5. Cross-field validation