Guest User

Untitled

a guest
Jan 15th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <html><head><title>Test</title></head><body>
  2.  
  3. <input type=text id="inputText" value="testValue" onInput=doIt(this);>
  4.  
  5. </body></html>​
  6.  
  7. var editedValue = "testValue";
  8.  
  9. // alert(editedValue);
  10.  
  11. function doIt(that)
  12. {
  13.  
  14. var caretPos = that.selectionStart;
  15.  
  16. if (that.value.indexOf(" ") != -1)
  17. {
  18. that.value = editedValue;
  19. // alert(caretPos);
  20. that.selectionStart = caretPos;
  21. }
  22. else
  23. {
  24. editedValue = that.value;
  25. }
  26.  
  27. }​
  28.  
  29. function doIt(e)
  30. {
  31. var e = e || event;
  32.  
  33. if (e.keyCode == 32) return false; // 32 is the keycode for the spacebar
  34.  
  35. }
  36.  
  37. window.onload = function(){
  38. var inp = document.getElementById("inputText");
  39.  
  40. inp.onkeydown = doIt;
  41. };
  42.  
  43. function pasteIt(e)
  44. {
  45. var e = e || event;
  46.  
  47. this.value = this.value.replace(/s/g,'');
  48.  
  49. }
  50.  
  51. function pasteIt(e)
  52. {
  53. var e = e || event;
  54. var data = e.clipboardData.getData("text/plain");
  55.  
  56. if (data.match(/s/g)) return false;
  57. }
  58.  
  59. function bindEvents()
  60. {
  61. $(inputText).bind('keydown paste', checkForSpaces);
  62. }
  63.  
  64. function checkForSpaces()
  65. {
  66. if (event.type == "keydown" && event.which == 32) {return false;}
  67. if (event.type == "paste" && event.clipboardData.getData('text/plain').indexOf(" ") != -1) {return false;}
  68. }
Add Comment
Please, Sign In to add comment