Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html><head><title>Test</title></head><body>
- <input type=text id="inputText" value="testValue" onInput=doIt(this);>
- </body></html>
- var editedValue = "testValue";
- // alert(editedValue);
- function doIt(that)
- {
- var caretPos = that.selectionStart;
- if (that.value.indexOf(" ") != -1)
- {
- that.value = editedValue;
- // alert(caretPos);
- that.selectionStart = caretPos;
- }
- else
- {
- editedValue = that.value;
- }
- }
- function doIt(e)
- {
- var e = e || event;
- if (e.keyCode == 32) return false; // 32 is the keycode for the spacebar
- }
- window.onload = function(){
- var inp = document.getElementById("inputText");
- inp.onkeydown = doIt;
- };
- function pasteIt(e)
- {
- var e = e || event;
- this.value = this.value.replace(/s/g,'');
- }
- function pasteIt(e)
- {
- var e = e || event;
- var data = e.clipboardData.getData("text/plain");
- if (data.match(/s/g)) return false;
- }
- function bindEvents()
- {
- $(inputText).bind('keydown paste', checkForSpaces);
- }
- function checkForSpaces()
- {
- if (event.type == "keydown" && event.which == 32) {return false;}
- if (event.type == "paste" && event.clipboardData.getData('text/plain').indexOf(" ") != -1) {return false;}
- }
Add Comment
Please, Sign In to add comment