I have a textbox, where a forbidden character cant be typed. #.
This works, however, when the textbox is filled in with data, and I put the focus on the middle of th
You can prevent to execute your code if the user presses a right or a left arrow. To do this you just need to add this condition:
if(e.which != 37 && e.which != 39){
You can find the key codes here.
Your full code would be:
$('[id$=txtClient]').keyup(function () {
if(e.which != 37 && e.which != 39){
EnableClientValidateButton();
ChangeColorClient("0");
var $el = $('[id$=txtClient]');
var text = $el.val();
text = text.split("#").join("");
$el.val(text);//set it back on the element
}
});
LIVING EXAMPLE