如何限制在文本框中输入的特殊字符(ASP.NET,c#.net,jquery)。 [英] How to restrict the special characters being entered in textbox (ASP.NET, c#.net, jquery).

查看:89
本文介绍了如何限制在文本框中输入的特殊字符(ASP.NET,c#.net,jquery)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Hi 
如何限制在文本框中输入的特殊字符(ASP.Net,C#.Net,jQuery)。
我的当前验证按预期工作[当用户在文本框中输入时],
但问题是当用户复制特殊字符(#,{,},|)并粘贴到文本框中时失败它不起作用。
如何阻止用户在我的文本框中键入/复制粘贴特殊字符?

请帮助我。
谢谢。





我的尝试:



我的当前验证按预期工作[当用户在文本框中输入时],

但问题是当用户复制特殊字符(#,{,},|时失败)并粘贴到文本框然后它不起作用。

解决方案

Yugesh,试试这个:

 

(#txtBoxId)。bind(paste,function(e){
var pastedText = e.originalEvent.clipboardData.getData('text');
validate(pastedText);
});





请记住这次在验证功能中你必须验证任何粘贴的数据特殊人物存在。



希望有所帮助。


Hi 
How to restrict the special characters being entered in textbox (ASP.Net, C#.Net, jQuery).
My Current Validation is working as expected [when user types in textbox],
 but the problem is it’s getting failed when user Copy Special Characters (#,{,},|) and Paste into the textbox then it’s not working. 
How can I prevent the user to Type/Copy Paste Special Characters into my Textbox?

Please assist me. 
Thanks.



What I have tried:

My Current Validation is working as expected [when user types in textbox],
but the problem is it’s getting failed when user Copy Special Characters (#,{,},|) and Paste into the textbox then it’s not working.

解决方案

Yugesh, try this:


("#txtBoxId").bind("paste", function(e){ var pastedText = e.originalEvent.clipboardData.getData('text'); validate(pastedText); } );



Remember this time in validate function you have to validate whole pasted data for any special character presence.

Hope it helps.


这篇关于如何限制在文本框中输入的特殊字符(ASP.NET,c#.net,jquery)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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