JavaScript Prevent spaces in input field on keypress event prevent spaces input,prevent spaces in input field,prevent spaces

You may try this. I hope it helps.

var down = [];
$(document).keydown(function (e) {
     down[e.keyCode] = true;
}).keypress(function (e) {
     if (down[17] && down[32]) {
         var $sampleTextBox = $("input#sampleTextBox");
          $sampleTextBox.val($sampleTextBox.val().replace(/\s/g, ''));
         alert($sampleTextBox.val().length)
          alert("Ctrl + Space Pressed!");
     }
     down[e.keyCode] = false;
}).keyup(function (e) {
     if (down[17] && down[32]) {
         var $sampleTextBox = $("input#sampleTextBox");
          $sampleTextBox.val($sampleTextBox.val().replace(/\s/g, ''));
         alert($sampleTextBox.val().length)
          alert("Ctrl + Space Pressed!");
     }
     down[e.keyCode] = false;
});

--

Thanks,

SuperCoder

Answer:1

I need to chagen my JSON output which is: [ { masterCardNo: 90363.01 }, { masterCardNo: 90363.02 }, { masterCardNo: 90363004 }, { masterCardNo: 90363004 }, { ...

I need to chagen my JSON output which is: [ { masterCardNo: 90363.01 }, { masterCardNo: 90363.02 }, { masterCardNo: 90363004 }, { masterCardNo: 90363004 }, { ...

I'm trying to achieve the below result by ONLY using the "labels" class (eg. I don't want the "arrow" class/html). Is this possible with pseudo elements only? Like ".labels:tesing{}" etc. .labels{ ...

I'm trying to achieve the below result by ONLY using the "labels" class (eg. I don't want the "arrow" class/html). Is this possible with pseudo elements only? Like ".labels:tesing{}" etc. .labels{ ...

The problem is the same as in Close all HTML unclosed IMG tags, but the provided regexp (<img[^>]+)(?<!/)> requires lookbehind support - which nodejs does not have. How can I achieve the ...

The problem is the same as in Close all HTML unclosed IMG tags, but the provided regexp (<img[^>]+)(?<!/)> requires lookbehind support - which nodejs does not have. How can I achieve the ...

I have a 'beginner' question. Why does this error out? I call the function in the code, but the function is defined further down. AngularJS version: var myApp = angular.module('myApp',[]); function ...

I have a 'beginner' question. Why does this error out? I call the function in the code, but the function is defined further down. AngularJS version: var myApp = angular.module('myApp',[]); function ...