I have this JS function that prevents user from typing characters
// To Disable the paste functionality
$(document).ready(function(){
$('#txtInput').bind("paste",function(e) {
e.preventDefault();
});
});
// Below One might be helpful for your functionality.
$(document).ready(function(){
$('#txtInput').bind("paste",function(e) {
validate(e);
});
});
or
OnTabOut()
or onblur()
you can validate the entered / pasted text instead of handling the paste functionality.
If you simply need non editable kendoComboBox(), you could use kendoDropDownList() instead.
In my case i needed it to be enabled/disabled depending on user privileges, so here's the solution i came up with (this prevents key inputs and pasting values) :
if (user.hasRight()) {
var myinput = $("#myinput").data("kendoComboBox");
myinput.input.on("keydown", function (e) { e.preventDefault(); });
myinput.input.bind("paste", function (e) { e.preventDefault(); });
}
You can test it here
Very Easy Solution:
<input name="ReceiveNo" type="text" class="txtbox" onkeypress='validate(event)' maxlength="11" value="${cpCon.receiveNo}" required tabindex="34" onCopy="return false" onDrag="return false" onDrop="return false" onPaste="return false" autocomplete=off />
This worked for me very well. No one can paste now into your textbox using right button paste option of mouse or pressing ctrl+v from the keyboard.
I tried this in my Angular project and it worked fine without jQuery.
<input type='text' ng-paste='preventPaste($event)'>
And in script part:
$scope.preventPaste = function(e){
e.preventDefault();
return false;
};
In non angular project, use 'onPaste' instead of 'ng-paste' and 'event' instead of '$event'.
jQuery:
$(this).click(function () {
$(".txtbox").attr("disabled", "disabled");
});
or css:
.txtbox{
display: none;
visibility: hidden;
}
or html attribute:
set disabled="disabled";