Ionic-3 ion-input maxlength attribute not working

前端 未结 3 1996
予麋鹿
予麋鹿 2021-02-19 03:55

I have tried to add ion-input for maxlength , max attribute but it\'s not working as per expectation.



        
3条回答
  •  执笔经年
    2021-02-19 04:26

    I found my way out you can use below my code. great this about it is you can keep input type number so android will show keyboard of your desire

    put this code in your form builder

    phone: ['', [Validators.required, this.isValidNumber.bind(this)]]
    

    in your ts file add below method

    isValidNumber(fieldControl: FormControl) {
        if(this.formBuilderGroup) {
          return fieldControl.value.toString().length < 10 ? null : {
            NotEqual: true
          };
        }
      }
    

    in above code change formBuilderGroup to whatever your form builder group name it is. change 10 to whatever you prefer length

提交回复
热议问题