I'm facing an issue with a reactive form control that has multiple validators. Despite defining the validation methods, the form is not being validated as expected. Below is the code snippet illustrating my attempted solutions.
Method 1:
civilIdNumber: new FormControl("", Validators.compose([Validators.required, Validators.minLength(12), Validators.maxLength(12), Validators.pattern("^[0-9]*$")])),
Method 2:
civilIdNumber: new FormControl("", [Validators.required, Validators.minLength(12), Validators.maxLength(12), Validators.pattern("^[0-9]*$")])
HTML Code:
<form [formGroup]="customerForm">
<div class="col-sm-6">
<div class="form-group">
<label for="civil">Civil ID Number</label>
<input
type="number"
placeholder="Civil ID Number"
class="form-control"
id="civil"
formControlName="civilIdNumber"
required
[ngClass]="{ 'is-invalid': customerForm.controls.civilIdNumber.invalid && customerForm.controls.civilIdNumber.touched }"
/>
<div *ngIf="customerForm.controls['civilIdNumber'].invalid && (customerForm.controls['civilIdNumber'].dirty || customerForm.controls['civilIdNumber'].touched)" class="text-danger">
<div *ngIf="customerForm.controls['civilIdNumber'].errors.required">Civil ID Number required</div>
</div>
</div>
</div>
</form>