sridharan
sridharan

Reputation: 2065

Angular 7 min length validation error not showing reactive forms

Form validation min length validation error not showing i am using reactive forms

<div [formGroup]="subMerchant">
    <ion-item class="inputDesign">
            <ion-input placeholder="Enter Sub Merchant Mobile no" formControlName="SubMercMobileNo" type="tel" maxlength="10"></ion-input>
          </ion-item>
          <ion-text class="errorText" color="danger" *ngIf="subMerchant.controls.SubMercMobileNo.errors && submitted == true">
            <p [hidden]="!subMerchant.controls.SubMercMobileNo.errors.required">Mobile is required</p>
            <p [hidden]="!subMerchant.controls.SubMercMobileNo.errors.minlength">Enter minlength 10</p>
            <p [hidden]="!subMerchant.controls.SubMercMobileNo.errors.pattern">Enter valid is Mobile No</p>
          </ion-text>
</div>

  subMerchant: FormGroup;
 this.subMerchant = this.formBuilder.group({
      SubMercMobileNo: ['', Validators.compose([
        Validators.required,
        Validators.minLength(10),
        Validators.pattern("[0-9]{0-10}")
      ])],
 );

Upvotes: 1

Views: 6495

Answers (2)

siva kumar
siva kumar

Reputation: 579

<div [formGroup]="subMerchant">
<ion-item class="inputDesign">
        <ion-input placeholder="Enter Sub Merchant Mobile no" formControlName="SubMercMobileNo" type="tel" minlength="10"></ion-input>
      </ion-item>
      <ion-text class="errorText" color="danger" *ngIf="subMerchant.controls.SubMercMobileNo.errors && submitted == true">
        <p [hidden]="!subMerchant.controls.SubMercMobileNo.errors.required">Mobile is required</p>
        <p [hidden]="!subMerchant.controls.SubMercMobileNo.errors.minlength">Enter minlength 10</p>
        <p [hidden]="!subMerchant.controls.SubMercMobileNo.errors.pattern">Enter valid is Mobile No</p>
      </ion-text>

Upvotes: 4

Irshad Ali
Irshad Ali

Reputation: 1213

You have not used minlength="a number" on element

Upvotes: 0

Related Questions