I am using Angular 4. I want to allow the zipCode
input field to only take an input of length 5 or 7 digits.
HTML code:
<md-input-container class="fill-width-input-wrap">
<input mdInput placeholder="Zip Code" formControlName="zipCode" minLength="5" maxLength="7" (keypress)="allowOnlyNumbers($event)" required>
<md-error *ngIf="clientInformationForm.controls['zipCode'].hasError('required')">
Please enter
<strong>valid zipcode</strong>
</md-error>
<md-error *ngIf="clientInformationForm.controls['zipCode'].hasError('minLength')">
zip code
<strong>minimum length is 5</strong>
</md-error>
</md-input-container>
Validators.pattern(/[0-9]{5}/)
– Firedamp