Link to home
Start Free TrialLog in
Avatar of mickeyknox
mickeyknox

asked on

Javascript Pipe Replacement

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?
ASKER CERTIFIED SOLUTION
Avatar of GwynforWeb
GwynforWeb
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mickeyknox
mickeyknox

ASKER

Thanks, that worked out well.