not allow to click space in jquery code example

Example: disable paste space in textbox using javascript

// don't allow paster space from another source
restrict_allow_paste_space: function($ele){
  $ele.on('keypress', function(e) {
    if (e.which == 32){
      return false;
    }
  });
  $ele.on('paste', function(e) {
    e.preventDefault();
  });
},
  
  
// don't allow space when type username
<input type="search" name="username" id="login-username" class="form-control a4l-input"  onKeyDown="if(event.keyCode === 32) return false;" placeholder="<?php echo  __d('member', 'enter_usename')?>">