title: Allow html input box to only enter one full number and exactly decimal .5
body: <p>I'm making web application that requires users to enter number with one decimal place. I restrict users from entering other characters that numbers from using this javascript code</p>
  
  <p>html</p>
  
  <pre><code>&lt;input type="number" name='days' class="w3-input w3-padding-tiny" id="cntday"  onkeypress="return isNumberKey(event)" placeholder="Enter days"/&gt;
  </code></pre>
  
  <p>javascript</p>
  
  <pre><code>function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode != 46 &amp;&amp; charCode &gt; 31 &amp;&amp;
               (charCode &lt; 48 || charCode &gt; 57))
               return false;
            return true;
           }  
  </code></pre>
  
  <p>but this function only prevent users from entering characters other than numbers.
  I need to prevent users from entering more than one decimal places as well as entered decimal should be .5 </p>
  
  <p>it's like this </p>
  
  <ul>
  <li><p>if user enter 5.55 it should replace with  5.5 OR prevent user to input additional decimal</p></li>
  <li><p>and if user enter 5.2 OR any decimal it should be replace with 5.5 in other words users should only able to enter number with decimal .5 </p></li>
  </ul>
  
  <p>how can I achieve this with my current onkeypress function ?</p>
  
  <p>This is NOT a duplicate of the other question. Stop flagging this</p>