Introduction:
Here I will show how to use Javascript to allow only alphabets in textbox or how to make textbox to
allow only alphabets using javascript
<html> <div> <script type="text/javascript"> function IsAlpha(e) { // alert(e.keyCode); var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode; //65 to 90 is Capital letter : 97 to 122 is small letter : 32 is Space : Delete 127 var ret = ( (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (keyCode == 32) || (keyCode == 08) || (keyCode == 127)); // document.getElementById("error").style.display = ret ? "none" : "inline"; return ret; } </script> <input type="text" id="text1" onkeypress="return IsAlpha(event);" ondrop="return false;" onpaste="return false;" /> </div> </html>