Reputation: 663
How can i disallow paste in a textbox if the copied string contains white spaces
Upvotes: 2
Views: 774
Reputation: 5262
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
Upvotes: 0
Reputation: 18430
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('');
});
Upvotes: 0
Reputation: 14687
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
Upvotes: 0
Reputation: 30882
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.
Upvotes: 1