3
Answers

How to trim spaces when copy paste?

Raja

Raja

8y
344
1
I have multiline textbox now i copy the value from excel cell and paste to multi line textbox.Content is pasted but also paste the empty spaces also.so the content go to upside.so textbox is view like no contents are not available in textbox.
 
Double click the cell and copy the content and paste it paste correctly.but the whole cell is copied the spaces not trimmed(this is for user friendly purpose).
Answers (3)
0
Rajeesh Menoth

Rajeesh Menoth

NA 24.7k 629.4k 8y
Hi,
Please check the following reference :
http://stackoverflow.com/questions/40106009/how-create-text-box-which-not-allow-blank-space-using-javascript
Accepted
1
Pradeep Sahoo

Pradeep Sahoo

NA 5.8k 1.1m 8y
var text = document.getElementById('txtText');
text.addEventListener('input', function(e){
var keyCode = e.keyCode ? e.keyCode : e.which;
this.value = this.value.replace(/\s/g, '')
if(keyCode === 32) return;
})
<input type='text' id="txtText">
event code 32 represent white space .
1
Bikesh Srivastava

Bikesh Srivastava

NA 19.8k 835k 8y
  1. varel=document.getElementsByName("10010input")[0];
  2. varval=el.value.replace(/\s/g,"");
  3. alert(val);
You can use code like this..