robrodp
asked on
trim string in javascript function
I have this javascript functionin an asp script to validate some data:
if (document.Form1.Msg.value. length == 0) {
alert("Falta Mensaje")
return(false)
}
If the Msg has spaces it validates ok. How can I run the function trimming left and right spaces?
if (document.Form1.Msg.value.
alert("Falta Mensaje")
return(false)
}
If the Msg has spaces it validates ok. How can I run the function trimming left and right spaces?
ASKER
Can you post full syntax (function, etc) and how to pass it to my validation function
function strim(str)
{
while (str.substring(0,1) == ' ')
{
str = str.substring(1, str.length);
}
while (str.substring(str.length- 1, str.length) == ' ')
{
str = str.substring(0,str.length -1);
}
return str;
}
you can call the function just like any other function call
trimmedstring=strim(origin alstring);
{
while (str.substring(0,1) == ' ')
{
str = str.substring(1, str.length);
}
while (str.substring(str.length-
{
str = str.substring(0,str.length
}
return str;
}
you can call the function just like any other function call
trimmedstring=strim(origin
ASKER
I define the function fine...
Where does it fin in:
if (document.Form1.Msg.value. length == 0) {
alert("Falta Mensaje")
return(false)
So that the Msg variable is trimmed?
Where does it fin in:
if (document.Form1.Msg.value.
alert("Falta Mensaje")
return(false)
So that the Msg variable is trimmed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i can help u if you send the full function and what u are trying to do with the function. Part of the function alone (like the one u have given) does not make sense
ASKER
Let me work on it BBK
{
str = str.substring(1, str.length);
}
while (str.substring(str.length-
{
str = str.substring(0,str.length
}
str -> your string with spaces