I am working on an application where I am implementing max length but it is not working. below is my implementation
TS
this.customPaymentForm = new FormGroup({ amount: new FormControl(0, [Validators.required, Validators.pattern(/^\d{1,4}(\.\d{1,2})?$/)]), cVVCode: new FormControl('', [Validators.required,Validators.maxLength(4)), }) HTML
<div class="input"> <label for="">Cryptogramme visuel <span class="req">*</span></label> <input type="number" class="form-control" formControlName="cVVCode" placeholder="XXXX" /> <div class="text-error" *ngIf="customPaymentForm.get('cVVCode').errors && (customPaymentForm.get('cVVCode').touched || customPaymentForm.get('cVVCode').dirty)"> <div *ngIf="customPaymentForm.get('cVVCode').hasError('required')">Cryptogramme visuel est requis.</div> <div *ngIf="customPaymentForm.get('cVVCode').hasError('maxlength')">Cryptogramme visuel doit avoir au maximum 4 caractères.</div> </div> </div> It doesn't show an error message.