title: Remove "$" before ASP.Net RangeValidator script executes
body: <p>How can I force the input's onchange script to run <em>before</em> the RangeValidator's script?  </p>
  
  <p>I want to prevent a failed validation when the user enters a dollar sign or comma.</p>
  
  <pre><code>function cleanUp(str) {
      re = /^\$|,/g;
      return str.replace(re, ""); // remove "$" and ","
  }
  
  &lt;input type="text" id="salary" runat="server"
  onchange="this.value=cleanUp(this.value)" /&gt;
  
  &lt;asp:RangeValidator ID="salaryValidator" 
      runat="server" ErrorMessage="Invalid Number"
      ControlToValidate="salary" Type="Double" /&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong> <br />
  I decided to use a CustomValidator that checks the range and uses a currency RegEx.  Thanks Michael Kniskern.</p>
  
  <pre><code>function IsCurrency(sender, args) {
      var input = args.Value;
  
      // Check for currency formatting.
      // Expression is from http://regexlib.com/REDetails.aspx?regexp_id=70
      re = /^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$/;
      isCurrency = input.match(re);
  
      if (isCurrency) {
          // Convert the string to a number.
          var number = parseFloat(CleanUp(input));
          if (number != NaN) {
              // Check the range.
              var min = 0;
              var max = 1000000;
              if (min &lt;= number &amp;&amp; max &gt;= number) {
                  // Input is valid.
                  args.IsValid = true;
                  return;
              }
          }
      }
  
      // Input is not valid if we reach this point.
      args.IsValid = false;
      return;
  }
  
  function CleanUp(number) {
      re = /^\$|,/g;
      return number.replace(re, ""); // remove "$" and ","
  }       
  
  &lt;input type="text" id="salary" runat="server" /&gt;
  
  &lt;asp:CustomValidator ID="saleryValidator" ControlToValidate="salary" runat="server" 
  ErrorMessage="Invalid Number" ClientValidationFunction="IsCurrency" /&gt;
  </code></pre>