Javascript examples for jQuery Method and Property:keypress
Validation with jQuery key press event handler
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.6.4.js"></script> <script type="text/javascript"> $(window).load(function(){/* ww w . java 2 s. c o m*/ $("#txtBox").keypress(function (e) { var input = $(this).val() + String.fromCharCode(e.which); if (input.split(',').length > 4) { e.preventDefault(); } }); }); </script> </head> <body> <input id="txtBox"> </body> </html>