Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Monday, April 22, 2013

jQuery Allow Only Alphabets in Textbox using JavaScript


To allow only alphabets in textbox using JQuery we need to write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Allow only alphabets in textbox using jquery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtNumeric').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>
<div>
<b>Enter Text:</b><input type="text" id="txtNumeric" />
</div>
</body>
</html>

No comments:

Post a Comment