?
Solved

Javascript Pipe Replacement

Posted on 2005-04-08
2
Medium Priority
?
1,826 Views
Last Modified: 2010-05-18
I'd like to replace the pipe character "|" w/ nothing in a text box on a web page using Javascript. I've successfully done this with the # character, however, I can't seem to make the | character work. Here is what I have in my "onkeypress" function (well, part of it)...

      searchTerm = document.getElementById(fromId).value;
      var POUND         = new RegExp( '#',  'g' );
      searchTerm = searchTerm.replace(POUND,'');
      var PIPE         = new RegExp( '\|',  'g' );
      searchTerm = searchTerm.replace(PIPE,'');
      document.getElementById(fromId).value = searchTerm;

It isn't recognizing the | symbol for some reason. I know this is something simple that I'm missing. I know the pipe symbol is special in reg exp, but I am trying to escape it with the use of the backslash. Help?
0
Comment
Question by:mickeyknox
2 Comments
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 200 total points
ID: 13738026
\ has special meaning as well in a string use

     var PIPE         = new RegExp( '\\|',  'g' );
0
 

Author Comment

by:mickeyknox
ID: 13739433
Thanks, that worked out well.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question