Mathew Paul
Mathew Paul

Reputation: 663

Text box pasting issue

How can i disallow paste in a textbox if the copied string contains white spaces

Upvotes: 2

Views: 774

Answers (5)

mirfan00
mirfan00

Reputation: 129

You can write some logic in TextChanged event of TextBox.

Upvotes: 0

Terry
Terry

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

Shekhar_Pro
Shekhar_Pro

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

Charbel
Charbel

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

m.edmondson
m.edmondson

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

Related Questions