Jquery control input field by length - Javascript jQuery

Javascript examples for jQuery:Form Input

Description

Jquery control input field by length

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script> 
  <script type="text/javascript">
    window.onload=function(){//w  w  w .j a  v a  2  s .c o  m
$('input').on('input',function(){
   var val=this.value;
    if(val.length>4)
       this.value=this.value.substring(1);
})
    }

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

Related Tutorials