I want to disable consecutive multiple spaces in an asp.net textbox using jQuery.
The text field should not accept something like
Hello World
$(document).ready(function () {
$('#txtFeedDesc').keydown(function (e) {
if (e.ctrlKey || e.altKey) {
e.preventDefault();
}
else {
var key = e.keyCode;
var name = document.getElementById('<%=txtFeedDesc.ClientID %>').value;
if (!((key == 8) || (key == 32) || (key == 42) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
return false;
}
else {
if (name.length < 50 || key == 8) {
return true;
}
else {
return false;
}
}
}
});
});
This is a text box that accepts alphanumeric characters. I do not want two consecutive spaces
source
share