View:
https://blog.csdn.net/iotjin/article/details/112526267
Recently when adding regular expressions in the input search box, I found that the iOS native keyboard always entered Chinese characters abnormally, while the Android phone had no abnormalities, and the abnormal writing method appeared:
html
<input id="inputId" type="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="请输入"
maxlength="30"
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')">
1
After processing:
html
<input id="inputId" type="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="请输入"
maxlength="30">
2
js
//实时录入时通过正则剔除特殊字符(只能输入中文数字字母空格),此方式可解决iOS原生键盘中文录入异常
var flag = false;
$('#inputId').on({
'compositionstart': function () {
flag = true;
},
'compositionend': function () {
flag = false;
if (!flag) {
document.getElementById("inputId").value = document.getElementById("inputId").value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g, '');
}
},
'input propertychange': function () {
if (!flag) {
document.getElementById("inputId").value = document.getElementById("inputId").value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g, '');
}
}
});
```