Angular 2 creating a common validation service to be used across all the Angular 2 Reactive forms

Every day we come across web forms and we will have to do many validations, to check if user is entering the collect data, in correct format. Easiest way to do this is to have a service to do all your validations and we can keep on improving this validation service as we go and end of the project we will have a complete validation service to use in next project.

This is my ValidationService.ts

In your form obviously you will have to dependency inject this service, then you can initialise the form like below.

Happy validation.

Leave a comment