I have a reactive form that has two fields: searchType and number. The field searchType can be '0' or '1' only. number is a number and number has some validation.
this.searchForm = this.formBuilder.group({
searchType: ['0'],
number: [
undefined,
[ Validators.required, Validators.minLength(6) ]
]
});
But now I want to add some specific validator for number only if searchType is 1. For example if searchType is 0 I have to use [ Validators.required, Validators.minLength(6) ], but if searchType is 1 I have to use [ Validators.required, Validators.minLength(8), Validators.minLength(20)]. How can I do that?