【问题标题】:Input validation working in web but not in andriod/ios Ionic输入验证在 web 中有效,但在 android/ios 中无效
【发布时间】:2020-10-23 22:59:26
【问题描述】:

在我的搜索栏中,我已经实现了模式验证。

所以基本上我想限制用户在搜索栏中输入数字和一些特殊字符。 html文件

<ion-searchbar animated searchIcon=undefined clearIcon=undefined 
  [(ngModel)]="searchTerm"
  (ionFocus)="focusInput($event)" 
  (ionChange)="filteredItems()" 
  placeholder="Search for product" 
  (keypress)="validateProductSearch($event)" 
  (ionInput)="validateProductSearch($event)" 
  (keyup)="validateProductSearch($event)" >
 </ion-searchbar>

ts 文件-

validateProductSearch(event: any) {
    const pattern = /^[a-zA-Z\_\-',.:`"() ]*$/
    let inputChar = String.fromCharCode(event.charCode);
    if (!pattern.test(inputChar)) {
      event.preventDefault();
    }
  }

这是在网络浏览器中工作的。但是当我在手机/平板电脑中安装 apk 时,此验证不起作用。 我尝试过 IonInput、Keyup 和 Key press。

用户可以输入任何内容。

使用 ionic 5 版本。

提前致谢

【问题讨论】:

    标签: angular ionic-framework ionic2 ionic3


    【解决方案1】:

    keypress 更改为 ionInput,如 docs

    中所述

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 2013-05-16
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2013-01-16
      相关资源
      最近更新 更多