Textarea with javascript validation during key pressed event - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

Textarea with javascript validation during key pressed event

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  ww  . ja v a 2 s.c  o  m*/
document.querySelector('.input').onkeypress = function validate(e) {
    if (String.fromCharCode(e.keyCode).match(/[A-Za-z0-9,-]/) == null) {
        console.log('not allowed');
        e.preventDefault();
    }
};
    }

      </script> 
   </head> 
   <body> 
      <textarea name="pt_text" rows="8" cols="8" class="input"></textarea>  
   </body>
</html>

Related Tutorials