title: asp.net regular expression validator client side script error
body: <p>I have the following regular expression validator to detect whether an input string contains HTML/script tags and if so cause a vaidation error:</p>
  
  <pre><code>&lt;asp:TextBox ID="txt" runat="server" /&gt;
      &lt;asp:RegularExpressionValidator 
          ControlToValidate="txt" 
          runat="server"
          ID="regexVal"
          EnableClientScript="true"  Display="Dynamic"
          ErrorMessage="Invalid Content" 
          Text="!" 
          ValidationExpression="&gt;(?:(?&lt;t&gt;[^&lt;]*))" /&gt;
  </code></pre>
  
  <p>When I run the page hosting this markup I get a scipt error with the message "Syntax Error in Regular Expression".
  However when I take the same regex and run it using Regex class from System.Text.RegularExpressions everything works fine:
  Like so:</p>
  
  <pre><code>Regex r = new Regex("&gt;(?:(?&lt;t&gt;[^&lt;]*))");
  r.IsMatch(@"&lt;b&gt;This should cause a validation error&lt;/b&gt;");
  r.IsMatch("this is fine");
  </code></pre>
  
  <p>What am I missing</p>
  
  <p>UPDATE:
  The error seems to be happening in the following js function in WebResource.axd:</p>
  
  <pre><code>function RegularExpressionValidatorEvaluateIsValid(val) {
      var value = ValidatorGetValue(val.controltovalidate);
      if (ValidatorTrim(value).length == 0)
          return true;
      var rx = new RegExp(val.validationexpression); //this is the line causing the error
      var matches = rx.exec(value);
      return (matches != null &amp;&amp; value == matches[0]);
  }
  </code></pre>