<div class="demo-wrap">
<input class="demo-input" type="text" />
<div class="demo-input-info"> Spaces between words are not allowed </div>
</div>
.demo-wrap {
margin: 0 auto;
padding: 2em;
max-width: 340px;
}
.demo-input {
font-size: 2em;
}
.demo-input-info {
font-size: small;
}
$(document).ready(function() {
$(".demo-input").on({
keydown: function(event) {
if (event.which === 32)
return false;
},
change: function() {
this.value = this.value.replace(/\s/g, "");
}
});
});