Search iEntry News



Stripping Out Bad Characters Generated By A Perl Shopping Cart

By Chris Crum
Staff Writer
Article Date: 2007-08-24

There is an interesting thread in the WebProWorld forum that solves a problem a member was having trying to strip bad characters from a block of text generated by his perl shopping cart.

The member's initial post reads:
I'm trying to strip our bad characters from a block of text with javascript. This seems to work sometimes but not others and I think it has to do with me not stripping out all the bad characters.

Of course, I could be completely wrong.

Here is my code so far, which truncates the resulting text:

<script type="text/JavaScript">

var outputstr = "!---TEXT---"
var textpreview = outputstr.replace(/[^a-zA-Z 0-9]+/g,'')

if (textpreview.length > 50)
{
document.write(textpreview.substr(0,50) + " ...")
}
else
{
document.write(textpreview)
}
</script>

The !---TEXT--- is a text file created by our shopping cart and holds product information. I thought I was only returning A-Z and 0-9 with my regex but I'm not sure if I'm doing it correctly.

Now, I said it work sometimes and not with others. The major difference I see with the ones that work and the ones that don't is that there are quotes "" in the text or there may be some html in the text.

A. Would this cause the javascript to break?

B. If so, what can I do?

C. Am I completely wrong about why it's not working?

D. Just give up this javascript stuff because I don't know what the hell I'm doing.
Watch the mystery unravel by reading the rest of the thread.

About the Author:
Chris is a staff writer for WebProNews. Visit WebProNews for the latest ebusiness news.




Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact

PerlProNews is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal