在文本框中复制粘贴时,不要显示字符串中的无效字符 [英] Don't show the invalid characters from string when copy paste in text box

查看:87
本文介绍了在文本框中复制粘贴时,不要显示字符串中的无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我创建了带有多个文本框的Windows窗体。



之一那些文本框不接受以下字符,如'=','\'。



如果用户输入这些字符,需要显示气球弹出消息作为'以下字符无效:\ =。



我在'按键'事件中执行此操作以防止这些字符和显示消息。 />


但是,在复制粘贴文本框中的这些无效字符时,首先显示所有字符然后删除无效字符。(因为在'文本已更改'事件中,我已逐一阅读,然后删除无效字符。)并显示气球消息。



即使我复制,如何不显示字符串中的无效字符粘贴在文本框中。

(例如:'xyz = fg \')它应该只显示'xyzfg'和气球弹出消息。



对此有何帮助?



提前致谢。

Dear All,

I have created Windows form with multiple Text boxes.

one of those text box does not accept the following characters like '=', '\' .

If user enters these characters, need to display a balloon pop-up message as 'The following characters are not valid: \ = ".

I have done this in 'Key Pressed' event to prevent these characters and displayed message.

But, while doing Copy Paste these invalid characters in text box, first it displays all the characters and then it removes invalid characters. (Since in 'Text changed' event, i have read the one by one and then removing invalid characters). and displayed a balloon message.

How to don't show the invalid characters from string even if i copy paste in text box.
(Ex: 'xyz=fg\') it should display only 'xyzfg' and balloon pop-up message.

Any help on this?

Thanks in advance.

推荐答案

试试这个



Try this


' #txtname')。bind(' keypress ',函数( event ){
var regex = / [!` 〜:; '\ ^ *%
('#txtname').bind('keypress', function (event) { var regex = /[!`~:;"'\^*%


{} [\ ?]#及())_ \\<> + / |] / GI;
var key = String.fromCharCode(!event.charCode?event.which:event.charCode);
if(regex.test(key)){
event.preventDefault();
返回false;
}
})。bind('paste',function(event){

var el =
{}[\]#&())_?\\<>+/|]/gi; var key = String.fromCharCode(!event.charCode ? event.which : event.charCode); if (regex.test(key)) { event.preventDefault(); return false; } }).bind('paste', function (event) { var el =


这篇关于在文本框中复制粘贴时,不要显示字符串中的无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆