Allow Only Alphabets In Textbox Using JavaScript
In this post we will discuss how to Allow Only Alphabets In Textbox Using JavaScript.I have already discussed Allow Only Numbers In Textbox Using JavaScript.I am using jQuery for this to achieve.
Code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Allow Only Alphabets In Textbox Using JavaScript</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script> <script type="text/javascript"> $(function () { $('#txtalpha').keydown(function (e) { if (e.shiftKey || e.ctrlKey || e.altKey) { e.preventDefault(); } else { var key = e.keyCode; if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) { e.preventDefault(); } } }); }); </script> </head> <body style="margin:0px auto;width:900px;text-align:center"> <div> <br/><br/> <h2>Allow Only Alphabets In Textbox Using JavaScript</h2> <b>Enter Text:</b><input type="text" id="txtalpha" /> </div> </body> </html>