Limit characters to Letters and Numbers in input field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

Limit characters to Letters and Numbers in input field

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w w w.  j  a v  a 2 s .c om*/
document.getElementById('input-nickname').onkeyup = function(event) {
    this.value = this.value.replace(/[^a-z\d]/, '');
}
    }

      </script> 
   </head> 
   <body> 
      <input type="text" id="input-nickname">  
   </body>
</html>

Related Tutorials