Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I need to validate the incoming string for text "<script".

Eg: string a = "This is a simple <script> string";
Now I need to write a regular expression that will tell me, whether this string contains <script> tag or not.

I ended up writing something like: <*?script.*?>

But the challenge is,
Incoming string may contain script in following ways,

1. string a = "This is a simple <script> string";
2. string a = "This is a simple < script> string";
3. string a = "This is a simple<javascript></javascript> string";
4. string a = "This is a simple <script type=text/javascript> string";

Hence the regular expression should check for starting "<" tag and then it should check for "script"

Please suggest.
Posted
Updated 16-May-13 3:22am
v6
Comments
Johnny J. 16-May-13 9:23am    
Sorry, I had to remove the <> from the subject row - it was f***ing up the layout of the Q&A forum
kulkarni.ajay 16-May-13 11:07am    
@Johnny: Sorry for disturbing Q&A forum layout.
Mohibur Rashid 16-May-13 9:46am    
if you want to execute script, then use jquery, would much simpler

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900