|
-
Aug 14th, 2002, 08:34 PM
#1
Thread Starter
Lively Member
How to eliminate blank spaces from a character or numeric filed
Hi,
I like to eliminate blank spaces from a character or numeric filed. Is there any function like Trim() to get rid of all the blank spaces from the right or left site of the filed by using JavaScript?
objValue =" ABC " or objValue = " 1233 "
FieldLength =anyFunctionName(eval(objValue.value.length))
Thanks,
Naci
-
Aug 15th, 2002, 02:04 AM
#2
You have to use the string object, then call a regular expression on it like the following :
Code:
<HTML>
<HEAD>
<SCRIPT Language="Javascript">
<!--
function TrimIt()
{
var strobjTextBox;
strobjTextBox = document.all.textbox1.value;
alert ("The Trimmed Text is :" + "'" +
strobjTextBox.replace(/^\s+|\s+$/g, "") + "'");
}
-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT Type="text" id="textbox1">
<BR><BR>
<INPUT Type="Button" id="cmdTrimTxt" Value="Click To Trim Text!"
onclick="TrimIt()">
</BODY>
<HTML>
-
Aug 15th, 2002, 02:05 AM
#3
btw, there is a different forum for javascript questions for another time
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|