Restricting input to textbox and allowing only numbers and decimal point - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

Restricting input to textbox and allowing only numbers and decimal point

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script language="Javascript">
    function check(e, value) {// w w w  .  j ava2s .  c  om
      //Check Charater
      var my = e.charCode ? e.charCode : e.keyCode;
      if (value.indexOf(".") != -1)
        if (my == 46) return false;
      if (my != 8)
        if ((my < 48 || my > 57) && my != 46) return false;
    }
  
      </script> 
   </head> 
   <body> 
      <input id="txtChar" onkeypress="return check(event,value)" type="text" name="txtChar">  
   </body>
</html>

Related Tutorials