custom validation reactive form angular 6 code example

Example 1: ng2 validations angular using reactiveforms

<form [formGroup]="form">
  <input type="password" formControlName="password"/>
  <p *ngIf="form.controls.password.errors?.required">required error</p>
  <input type="password" formControlName="certainPassword"/>
  <p *ngIf="form.controls.certainPassword.errors?.equalTo">equalTo error</p>
</form>

Example 2: validation minlength angular

Validators.minLength(9)

Example 3: angular9+how+to+add+validators

this.form.controls["firstName"].setValidators([Validators.minLength(1), Validators.maxLength(30)]);