title: How to allow numeric (0-9) & decimal value textbox using jQuery?
body: <p>i wrote few line to accept only numeric character but my script is not working. when i type any alphabet then it is getting inserted into textbox which i do not want. i want that textbox should accept only numeric value and "." point for decimal. here is my script. just tell me what is wrong there.</p>
  
  <pre><code> $().ready(function () {
          $("input[id*='txtQty']").keyup(function (event) {
              var flag = false;
  
              if (event.shiftKey == true) {
                  event.preventDefault();
              }
              // Allow Only: keyboard 0-9, numpad 0-9, backspace, tab, left arrow, right arrow, delete
              if ((event.keyCode &gt;= 48 &amp;&amp; event.keyCode &lt;= 57) || (event.keyCode &gt;= 96 &amp;&amp; event.keyCode &lt;= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46) {
                  // Allow normal operation
                  flag = true;
              } else {
                  // Prevent the rest
                  event.preventDefault();
              }
  
              if (flag) {
  
              }
          });
      });
  </code></pre>
  
  <p>if possible please give me script which will enable my textbox only numeric and decimal number. thanks</p>
  
  <p>here is my full script. the problem is it is taking dot <strong>"."</strong> which i dont want.</p>
  
  <pre><code>        $().ready(function () {
          $("input[id*='txtQty']").keydown(function (event) {
              var flag = true;
  
              if (event.shiftKey == true) {
                  event.preventDefault();
                  flag = false;
              }
  
              if ((event.keyCode &gt;= 48 &amp;&amp; event.keyCode &lt;= 57) || (event.keyCode &gt;= 96 &amp;&amp; event.keyCode &lt;= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46 || event.keyCode == 190) {
  
              } else {
                  event.preventDefault();
                  flag = false;
              }
  
              if (flag) {
                  if (jQuery.trim(this.value) != "") {
                      if (IsNumeric(jQuery.trim(this.value)) == true) {
                          var Symbol = $("span[id*='lblPrice']").text().trim().substring(1, 0);
                          var oldprice = $("input[id*='txtHiddenPrice']").val();
                          var newprice = Math.round((oldprice * this.value), 2);
                          $("span[id*='lblPrice']").text(Symbol + newprice);
                          UpdateCart($(this).closest('tr').find("input[id*='txtItemId']").val(), $(this).closest('tr').find("input[id*='txtProductId']").val(), this.value);
                      }
                  }
              }
          });
      });
  </code></pre>
  
  <p>so tell me what i need to change in my code as a result it should not take decimal value.
  another important thing i attach keydown() event with wild card system because my page may have many textbox with name end like <strong>txtQty</strong>.</p>
  
  <pre><code> $("input[id*='txtQty']").keyup(function (event) {
  </code></pre>
  
  <p>so please help me. thanks</p>