Adding Validators

In this lesson, we'll add some validators to the form controls we created in the previous lesson.

We'll cover the following

The next step in our journey is to add some validators to the form controls. We’ll be creating some custom validators soon, but first, let’s add some that we’re already familiar with. It’s always a good idea to take advantage of the validators that come with Angular before creating your own. This way, you can quickly identify what needs to be added.

Adding validators

We’re going to add validators to the registration form first. Users won’t be able to login if they can’t create an account. Thus, we’ll work on the registration form first.

In the register.component.ts component class file, let’s add validators by importing them.

Get hands-on with 1200+ tech skills courses.