微软输入法正则bug

需求是不能输入一些特殊字,测试发现微软输入法下不能输入中文。搜狗输入法正常输入,限制字符正常。

代码如下:

$("#showcaseInput").on("keyup",function(){
     // ------- 此代码存在bug。
// var _this=$(this).val(); // _this = _this.replace(/[`~!@#$%^&*_-+=<>?:"{}|,./;'\[]·~!@#¥%……&*——-+={}|《》?:“”【】、;‘’,。、]/im,''); // $(this).val(_this);      // ------- 后经修改解决。 var IllegalString = "[`~!#$^&*()=|{}':;',\[\]#$%_-+@.<>/?!#¥……&*《》()——|{}【】‘;:”“'。,、?]‘’"; var textboxvalue = $(this).val(); var index = textboxvalue.length - 1; var s = textboxvalue.charAt(index); if (IllegalString.indexOf(s) >= 0) { s = textboxvalue.substring(0, index); $(this).val(s) } });
原文地址:https://www.cnblogs.com/swt-axios/p/14330757.html