Javascript Validation to allow only Letters

There is often a scenario where client want the user to enter only alphabets nothing else. Though the validations will fail at the Database level when there is data type mismatch. Like for example, we have a textbox for Age and user enter letters into it. The validation will surely fail as the datatype in table would be int/smallint.
 
So it is also wise enough to add validation at the Javascript level, so that when user tries to enter something absurd other than letters alert would come saying Please enter only alphabets.
This below snippet will surely be of help.
  1. <html>  
  2. <head>  
  3.     <title>allwon only alphabets in textbox using JavaScript</title>  
  4.      
  5. </head>  
  6. <body>  
  7.     <table align="center">  
  8.         <tr>  
  9.             <td>  
  10.                 <input type="text" onkeypress="return allowOnlyLetters(event,this);" />  
  11.             </td>  
  12.         </tr>  
  13.     </table>  
  14. </body>  
  15. </html>  
  1. <script language="Javascript" type="text/javascript">    
  2.     
  3. function allowOnlyLetters(e, t)   
  4. {    
  5.    if (window.event)    
  6.    {    
  7.       var charCode = window.event.keyCode;    
  8.    }    
  9.    else if (e)   
  10.    {    
  11.       var charCode = e.which;    
  12.    }    
  13.    else { return true; }    
  14.    if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))    
  15.        return true;    
  16.    else  
  17.    {    
  18.       alert("Please enter only alphabets");    
  19.       return false;    
  20.    }           
  21. }      
  22. </script>    
Please use this easy & simple snippet and try out your validation.
 
Hope this helps .
Thanks