473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simple Code Request.

Jim
Hello,

Could someone give me an example of a function which will strip all of the
following characters from a text field, and replace the SPACES with HYPHENS.
I have very little knowledge of writing functions, so if you could be fairly
specific, I would be very grateful.

Characters to be stripped:
'
,
..
@
!
"
£
%
(
)

And all spaces to be converted to:
-
Kind regards,

Jim.
Jul 23 '05 #1
1 998
Ivo
"Jim" wrote

Could someone give me an example of a function which will strip all of the
following characters from a text field, and replace the SPACES with HYPHENS. I have very little knowledge of writing functions, so if you could be fairly specific, I would be very grateful.

Characters to be stripped:
'
,
.
@
!
"
£
%
(
)

And all spaces to be converted to:
-


<script src="" type="text/javascript">//<![CDATA[
function strip( o ){
o.value = o.value.replace( /[',.@!"£%()]/g, '' ).replace( / /g, '-' );
}
//]]></script>

<form action="">
<input type="text" name="txt"
value="Strip ',.@!&quot;£%() and make ' ' -" />
<input type="button" value="Strip"
onclick="strip( this.form.elements.txt )" />
</form>

There are many ways you can set this up, but most will use regular
expressions as they can do in a single command what might otherwise require
a labyrinth of substring() and charAt() calls. This function strip(), called
by the button in the form, takes an input element as its parameter, and
performs two replace() actions on that element, the first to remove the
forbidden characters, the second to turn spaces into hyphens.

The first argument of each replace() is not a string, but a regular
expression delimited by slashes, and flagged 'global' with the 'g' after the
second slash, to make the regex replace all instances instead of just the
first.

The &quot; in the example string in the text field is an escaped a double
quote character.
hth
ivo

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Benny Alexander | last post by:
Hi, I am using a simple form 2 email program. I ama experienced programmer, But I feel very bad, as I am unable to fix this problem. All seems to be fine, But the mail is not reacing to my...
13
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
2
by: Tomas Vera | last post by:
Hello All, I've come across something that's probably simple, but I can't seem to figure out (probably 'cause it's Monday.. yeah, That's it). Anyway, how do I receive form information from a...
10
by: GeekBoy | last post by:
Okay, I have two identical web servers running Windows 2003 web server. I have an ASP.NET application which runs great on one of them. Dedicated IP address, behind our firewall, etc. Everyone's...
0
by: Dam6 | last post by:
Hello, Having a bit of trouble with a simple login page etc using an access db. (Using DW 2004 and databases from Sean R. Nicholson) I've created a virtual application, added the dw ctrls and...
15
by: gjoneshtfc | last post by:
Hello, I have a simple problem that I just cannot get my head around! I currently have the following line in my ASP recordset: Recordset1.Source = "SELECT * FROM MainTable ORDER BY Price ASC"...
5
by: GregO | last post by:
I am new to ASP and would like to know if anyone has a page that will display username, time, IP TIA - Grego
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.