开发者

Text box pasting issue

How can i disallow paste 开发者_运维知识库in a textbox if the copied string contains white spaces


Anything that has the ability to do this will require javascript - which the user can disable. You're must better validating server-side, possibly using one of the validation controls.


in C# you can handle the textchanged event, and search for a space, and do something if found. for example error message or clear the text or anything. That's pretty straight forward


instead of disabling which i don't think is feasible use javascript to validate that the textbox dosen't contain space.

But As sugested by slugester( in comments) here is a snippet in jQuery that removes whitespaces

$("#inputID").change(function(event) {
$("#inputID").html = $("#inputID").val().split(' ').join('');

});


If you really want to detect the paste event, you could use delegates to reach that goal.

This might be a start : Textbox Copy, Cut and Paste Events


You can write some logic in TextChanged event of TextBox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜