With help of Validator we can write custom validations easily. The validate method will handle input and the expected output.
“validate” method will accept Abstract Control as a parameter which will accept Form Group, Form Control and Form Array as values.
The method of data sanitization depends on the type of data and the context in which it is used.
If you wish to validate specific content such as RSS/Atom feeds or CSS stylesheets, Mobile OK content, or to find broken links, there are other validators and tools available.Forms Module will detect a form element and ng Form automatically.To register the input elements to our ng Form we should include ng Model for all elements.And the output of the validate method can be null or undefined or Validation Errors object if user enters invalid data.In the above code, At first we have created Age Validator Directive class implementing Validator interface and we are checking whether the age is between 18 and 85 in validate method and return the different state based on age conditions.