【发布时间】: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