title: Input Validation using Multiple Regex
body: <p>I have a text field in which users can enter numerical field with numerical operators. Following is a set of examples for valid input</p>
  
  <pre><code>1. &gt; 3
  2. &gt;= 3
  3. &lt; 3
  4. &lt;= 3
  5. &lt;&gt; 3 (NOT)
  6. 3 to 5 (RANGE)
  7. &lt;&gt; 3 to 5 (NOT RANGE)
  </code></pre>
  
  <p>I've the following logic which works. I iterate through each <code>regex</code> on <code>keyup</code>. I wanna know is there more elegant and better way to do this?</p>
  
  <pre><code>function myFunction() {
      var x, text;
  
      // Get the value of the input field with id="numb"
      x = document.getElementById("numb").value;
      var arrRegex = new Array("^&gt;=\\d+$", "^&lt;=\\d+$", "^&gt;\\d+$", "^&lt;\\d+$", "^\\d+$", "^&lt;&gt; \\d+$", "^&lt;&gt; \\d+ to \\d+$", "^\\d+ to \\d+$");
      c = false;
      for (i = 0; i &lt; arrRegex.length; i++) {
          var regex = new RegExp(arrRegex[i]);
          if (regex.test(x)) {
              c = true;
          }
      }
      if (c == true) {
          document.getElementById("numb").style.backgroundColor = "green";
  
      } else {
          document.getElementById("numb").style.backgroundColor = "red";
  
      }
  }
  </code></pre>