Click here to Skip to main content
14,935,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone please tell me how to remove spaces in textbox.i need urgently please
Posted
Updated 23-Nov-12 2:06am
v2

   
Try this.
JavaScript
<script type="text/javascript">
function removeSpace(){
	document.getElementById('myText').value = document.getElementById('myText').value.replace(" ","");	
}
</script>

HTML
<input type="text" id="myText" />
<input type="button" onclick="removeSpace()" value="Remove Space" />
   
try :
C#
var el = document.getElementsByName(&quot;10010input&quot;)[0];
var val = el.value.replace(/\s/g, &quot;&quot;);
alert(val)

or To remove spaces <pre> if it is between
JavaScript
<script language="javascript">

String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
$(function(){
    $("#idOfTextBoxHere").keyup(function(){
      $(this).val( $(this).val().ltrim());
    });
});

</script>
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900