We need to stop copy paste of few characters like ‘<‘ or ‘>’ or any characters which can be potentially dangerous.
I know we can set a property RequestValidation to false, but for some reason we would not want to do that.
What we want to do is when the user tries to paste a text in the textbox, we want to validate the text and do a pattern match against the defined list of characters to be filters.
We tried various textbox events like OnPaste (Works in IE as well as Mozilla, but in Mozilla we are not able to get the content from the clipboard), OnBlur (Works fine but does not works when clicked on checkbox with runat as Server) and few others with no real progress.
Would appreciate if anyone of you guys can help me and help me sooner as we are in deadlines!
Thanks a lot,
Atul
First of all, you really shouldn’t be accessing the user’s clipboard, even if some versions of IE allow it. For reasons of integrity, that’s simply nothing a browser should be dealing with. Either way, you could check the textbox value after paste, rather than inspecting the clipboard content during paste.
However, better still would probably be to perform this validation on submit. Try the built in regular expression validators. Because really, you worry about users submitting dangerous characters, right, not about the fact that they actually pasted them?
EDIT (example)