I have a trick that 100% works.
Define input like text, not number.
For instance:
<input placeholder="OTP" formControlName="OtpUserInput" type="text">
Then use a template that is part of the validation.
Like:
this.ValidOtpForm = this.formbuilder.group({ OtpUserInput: new FormControl( { value:'', disabled: false }, [ Validators.required, **Validators.minLength(6), Validators.pattern('[0-9]*')** ]), });
This means that we determine the type of input text that is suitable for the minimum length, and we also define the template (validation) for the numeric value so that we can perform both checks.
Remaining code:
<mat-error *ngIf="RegistrationForm.controls['Password'].hasError('minlength')">Use 6 or more characters with a mix of letters</mat-error> <mat-error *ngIf="ValidOtpForm.controls['OtpUserInput'].hasError('pattern')">Please enter numeric value.</mat-error>
source share