title: Input text box as positive/negative/floating number with max length 11
body: <pre><code>Number : &lt;input type="text" name="inputId" id="quantity" maxlength="11" /&gt;
  </code></pre>
  
  <p>When user enter input it should satisfy below conditions 
  1. Value can be positive or negative or floating with max length 11</p>
  
  <p>This is what I have written so far</p>
  
  <pre><code>$(document).ready(function () {
    //called when key is pressed in textbox
    $("#inputID").keypress(function (e) {
       //if the letter is not digit then display error and don't type anything
       if (e.which != 8 &amp;&amp; e.which != 0 &amp;&amp; (e.which &lt; 48 || e.which &gt; 57 || e.which == 45 )) {
          //display error message
           if(e.which == 45) {
                  var value = $("#quantity").val();
                  if(value.indexOf('-') !=  -1)
                  { 
                       var index = value.lastIndexOf('-');
                       if(index = 0){
                       return false;
                     }
                  }
  
           }
           else
           {
               $("#quantity").val("-");   
           }       
      }
     });
  });
  </code></pre>
  
  <p>I did not consider "." as of now only for negative sign should be at index zero.</p>
  
  <p>is there any better way to do this or modifying this code would be the right way to go.</p>
  
  <p>kindly suggest.</p>