jQuery

Disable space input in text fields

What does this jQuery snippet do?

This jQuery snippet prevents users from entering spaces (using the spacebar or pasted input) into any input element with the class .demo-input

Demo
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, "");
}
});
});