Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regex to modify the HTML being submitted

Posted on 2014-04-29
3
Medium Priority
?
164 Views
Last Modified: 2015-02-27
Just recently working on one of the websites i have, found one issue:

People were submitting complete iframe tag or complete embed tag inside the table column including the url to run the video..

How can i remove the html around it or santitize it to just keep the url inside intact and add that inside the table column and ignore other html elements

like an example here

<iframe width="420" height="345"
src="http://www.youtube.com/embed/XGSy3_Czz8k">
</iframe>

<embed
width="420" height="345"
src="http://www.youtube.com/v/XGSy3_Czz8k"
type="application/x-shockwave-flash">
</embed>

Open in new window


in the above cases, just remove the html tags and keep the src to insert into the table column,

well it is not happening everytime, couple of users doing this, so also wanna have check if that in form entry, the iframe or embed source is found, then continue..

regards
0
Comment
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 40033071
alert('<iframe width="420" height="345" src="http://www.youtube.com/embed/XGSy3_Czz8k"></iframe>'.match(/src="(.+?)"/)[1]);

So var src = tag.match(/src="(.+?)"/)[1];
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 40033087
@mplungjan - I have to test it, if this works in coldfusion serverside, i will post the results
0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 40634923
solved with minor modifications, thx
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question