AS3 Make user input safe for display in htmltext

82 Views Asked by At

I've been searching for a good hour or two for this but I haven't found anything to what I'm looking for. I'm making a chat application( socket server made in Python ) and it's working fine. The main chat area where messages are stored use HTML, it just displays the username in bold along with their avatar and message. The problem I'm having is how do I stop the user from entering HTML and messing with the main chat? I'm currently using regex "/<.*?>/g" to remove HTML tags however I'd rather let the user send things like

<p>Hi everyone</p>

but instead of parsing what was sent as HTML just normal text?

For example, right now. While a user is typing I'm using regex to remove

<whatever>

tags as soon as they're typed. What I want is for the user to be able to type

<b>bold text</b>

and send but not display it as bold and show the b tags.

Here's what "mainChat" text box looks like http://prntscr.com/46hd4t, this stores all messages Here's what "chatMessage" text box looks like http://prntscr.com/46hdc6, this is where the user writes their message

1

There are 1 best solutions below

4
On

Sites such as reddit and Stack Overflow use a standard called markdown for editing text that takes care of these issues. Some popular options for markdown editors include WMD, markitup and Epic Editor. Just Google markdown there are many options to choose from.