Prevent '0' to be the first char entered in a textbox - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Prevent '0' to be the first char entered in a textbox

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function Prevent(value) {/*from  w  ww . jav a2s  .  com*/
    var x = document.getElementById("testInput");
    if (value == '0') {
        x.value = '';
    }
}

      </script> 
   </head> 
   <body> 
      <input type="text" onKeyUp="Prevent(this.value)" id="testInput">  
   </body>
</html>

Related Tutorials