This is a discussion on How to remove space appearing before the string in textbox? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; The following codes in javascript helps to remove the space appearing before the text. <html> <head> &...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| The following codes in javascript helps to remove the space appearing before the text. <html> <head> <script type="text/javascript"> function Validate() { var e1= document.getElementById("textbox1").value; document.getElementById("textbox1").value = (e1.replace(/^\W+/,'')).replace(/\W+$/,''); var ElemValue = document.getElementById("textbox1").value; if(ElemValue.length==0) { alert("Enter Value"); } if(ElemValue.length!=0) { alert("The space before "+ElemValue+" is removed"); } } </script> </head> <body> <input type="text" id="textbox1"></input> <input type="button" id="btn1" value="Click" onClick="Validate()"></input> </body> </html> |
|
#2
| |||
| |||
| Hi, Dont you have Trim function in Javascript.Cant you use var str=" Hello "; str =str.Trim();
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
|
#3
| |||
| |||
| Hi, For trimming the string in all the sides,use the following code Code: function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
sString = sString.substring(1, sString.length);
while (sString.substring(sString.length-1, sString.length) == ' ')
sString = sString.substring(0,sString.length-1);
return sString;
}
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
|
#4
| |||
| |||
| Hi, For trimming only the left part of the string ,you can use Code: function LeftTrim(var sString)
{
while (sString.substring(0,1) == ' ')
sString = sString.substring(1, sString.length);
return sString ;
}
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
|
#5
| |||
| |||
| Hi, For trimming only the right part of the string ,you can use Code: function RightTrim(var sString)
{
while (sString.substring(sString.length-1, sString.length) == ' ')
sString = sString.substring(0,sString.length-1);
return sString;
}
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
|
#6
| |||
| |||
| Hi, The Substring you have used works fine.But the Trim() doesn't work in JS. |
|
#7
| |||
| |||
| I have the same problem and now it has been sorted! |
|
#8
| |||
| |||
| Hm, I agree, but here is an opinion Last edited by arjkhanna : 06-23-2009 at 07:47 PM. |
|
#9
| |||
| |||
| i need to remove all text from a text box that comes before the ":" and remove .... I have to type in several numbers before they start to appear from the right. ... What code would I use to go down the column and remove the spaces beween the ... how would I remove any text in a string that is between |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| display xml in textbox | arjkhanna | C# Programming | 4 | 05-28-2009 08:28 PM |
| Showing C# Intellisense in TextBox | arjkhanna | C# Programming | 3 | 05-25-2009 10:56 PM |
| textbox in Gridview | packirisamy | ASP and ASP.NET Programming | 2 | 07-22-2008 03:56 AM |
| What is diffrenece between string.compare and string.compareordinal | shaalini | ASP and ASP.NET Programming | 3 | 12-28-2007 09:46 PM |
| What's the easiest way to remove characters from the end of a string in php? | oxygen | PHP Programming | 1 | 07-26-2007 01:53 AM |
Our Partners |