`
hueng512
  • 浏览: 27499 次
  • 性别: Icon_minigender_1
  • 来自: 打工子哥
社区版块
存档分类
最新评论

keypress事件和paste事件禁止特殊字符输入

 
阅读更多
content.find('#base_set_panel_name').keypress(function(e){
                            return ($.inArray(e.charCode || e.keyCode, [126, 96, 33, 64, 35, 36, 37, 94, 38, 42, 40, 41, 43, 61, 124, 92, 123, 91, 125, 93, 34, 39, 58, 59, 63, 47, 62, 60, 44, 46]) >= 0) ? false : true;
                        }).bind('paste', function(e) {
                            var text = this;
                            setTimeout(function() {
                                text.value = text.value || '';
                                //删除特殊字符
                                text.value = text.value.replace(/[~`,!@#$%^&*()+=|\\:;\'"\?/><,.]+/gi, '');
                                //IE下粘贴后不能自动触发change事件,这里要手动触发一下
                                if (document.attachEvent) {
                                    content.find('#base_set_panel_name').change();
                                }
                            }, 100);
                        });
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics