How can you disable spaces in an HTML input field?
To prevent spaces from being entered in an HTML input field using jQuery, you can attach a keydown event handler and check if the pressed key is the spacebar.
HTML
<div class="demo-wrap">
<input class="demo-input" type="text" />
<div class="demo-input-info">Spaces are not allowed</div>
</div>
JS
$(document).ready(function() {
$(".demo-input").on({
keydown: function(event) {
if (event.which === 32)
return false;
},
change: function() {
this.value = this.value.replace(/\s/g, "");
}
});
});
Alternate table row styles
Conditional formatting of table rows
Copy text to clipboard
Disable spaces in an input field
Multi step form with progress indicator
Read more or less
Remove the leading and trailing space
Short functions
Toggle visibility with a slide effect
Toggle visibility without pushing content down
Validate checkboxes
Validate input fields
Validate radio buttons
Validate TinyMce editor