如何在ionic2中验证aadhar卡?

时间:2017-09-27 09:48:23

标签: angular ionic2

aadharValid(): ValidatorFn {
    return (control: AbstractControl): { [key: string]: any } => {
      var re = new RegExp(/\d{4}\s\d{4}\s\d{4}$/);
      this.aadharInput = control.value;
      let isValid = re.test(this.aadharInput);
      if (!isValid)
        return { 'aadharValid': { isValid } }
      else
        return null;
    };
  }

HTML:

<ion-item> 
    <ion-label floating>Aadhar Card Number</ion-label> 
    <ion-input type="tel" maxlength="12" [(ngModel)]="user.aadhar" spellcheck="false" minlength="12" maxlength="12" formControlName="aadhar"></ion-input> 
</ion-item> 
<ion-item no-lines *ngIf="( user.get('aadhar').hasError('aadharValid')) && user.get('aadhar').touched"> 
    <div class="error" *ngIf="user.get('aadhar').hasError('aadharValid') && user.get('aadhar').touched"> Please enter valid Aadhar NO </div> 
</ion-item>

我得到了验证,但是如果我给出正确的输入意味着仍然显示错误

0 个答案:

没有答案