title: JQuery TextBox limit number onchange checks only first number
body: <p>I am working on a simple shopping cart application. (Asp.Net MVC5)
  I get product properties when you click the product inside a ListBox. A simple table shows productPrice and currentStock with Jquery and ajax.
  Then I want to prevent user to enter quantity bigger than currentStock quantity.</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.Quantity, new { htmlAttributes = new { id = "txtQuantity",
  onkeyup = "calculateTotal()", onchange = "calculateTotal()"} })
  </code></pre>
  
  <p>js code:</p>
  
  <pre><code>function calculateTotal() {
      var v = $('#txtQuantity').val();
      var stockQuantity = $('#lblStock').text();//This is where I get the current stock
      if (v &gt; stockQuantity) {
          $('#txtQuantity').val(stockQuantity);
      }
      var reTotal = $('#lblPrice').text() * $('#txtQuantity').val();
      $('#lblTotal').text(reTotal);
      };
  </code></pre>
  
  <p>This code works if you enter a bigger number than currentquantity.</p>
  
  <p>For example:</p>
  
  <p>currentQuantity= 7,</p>
  
  <p>When you enter 8 or 9. It changes to 7. But when you enter 65, 45, 1000 it does nothing. Because the first character of number is less than 7.</p>
  
  <p>How can I check whole number?</p>
  
  <p>P.S I can do this with [Remote] on model validation. But I just want to use this method.</p>