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(fr omId).valu e;
var POUND = new RegExp( '#', 'g' );
searchTerm = searchTerm.replace(POUND,' ');
var PIPE = new RegExp( '\|', 'g' );
searchTerm = searchTerm.replace(PIPE,'' );
document.getElementById(fr omId).valu e = 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?
searchTerm = document.getElementById(fr
var POUND = new RegExp( '#', 'g' );
searchTerm = searchTerm.replace(POUND,'
var PIPE = new RegExp( '\|', 'g' );
searchTerm = searchTerm.replace(PIPE,''
document.getElementById(fr
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER