Flash AS3 Tutorial: Remove HTML Tags

Leave a comment Standard

In my chat room one of the problems I ran into was formatting messages (ie adding font colors) but preventing users from posting HTML tags. So I came up with this nifty function. Run it on their content and then add your HTML to the resulting string. This way their HTML tags are ignored but yours aren’t.

private function stripTags(str:String)
{
	var validAlphaNumericRegExp:RegExp = /</gi;
	return str.replace(validAlphaNumericRegExp, "<");
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s