title: How to allow only characters on key press event for specific print range?
body: <pre><code>&lt;input type="text" name="RangeText" id="rangeNum" onkeypress = "printValidation(event)" /&gt;
  </code></pre>
  
  <p>I am trying to allow only characters on key press event for specific pages range in the above print selection text box. I can do this easily with regex but want user to type only valid sccenarios!</p>
  
  <p>What I want to achive is as shown in below examples:</p>
  
  <p>1  allow</p>
  
  <p>1-2 allow</p>
  
  <p>-2 not allow</p>
  
  <p>1, 2-3, 4, 5-7 allow</p>
  
  <p>1 2, 3 not allow</p>
  
  <p>1-2-2 not allow</p>
  
  <p>This is how my current funtion looks like, the tricky part seems is not allowing negative number to begin with but allow the hyphen in the range!</p>
  
  <pre><code>function printValidation(evt) {
      var charCode = (evt.which) ? evt.which : evt.keyCode;
      if (!evt.shiftKey &amp;&amp; !evt.altKey &amp;&amp; !evt.ctrlKey &amp;&amp; charCode &gt;= 48 &amp;&amp; charCode &lt;= 57 || charCode == 188 || charCode == 109) {
          alert("character accepted");
          return true;
      }else {
              alert("illegal character detected");
              return false;
          }
   }
  </code></pre>
  
  <p>Is there a possibility to achieve this without going in <a href="https://stackoverflow.com/questions/4468336/javascript-regular-expression-page-range-validation">regex</a> way?</p>