Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery - Allow Only Alphabets in Textbox using JavaScript

Apr 22, 2013
Introduction

Here I will show how to use JQuery to allow only alphabets in textbox or how to make textbox to allow only alphabets using JQuery.

Description:
  
In previous posts I explained
jQuery Allow only numbers in textbox, jQuery disable cut copy and paste options in textbox, jQuery Create Rounded Corners Textbox, jQuery slideUp, slideDown and slideToggle Example and many articles relating to JQuery, JavaScript, Asp.net. Now I will explain how to allow only alphabets in textbox using JQuery.

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>
Live Demo

To check live demo try to enter characters in below textbox


Enter Text:

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

12 comments :

Anonymous said...

I think this live demo is not working properly. Please check it.

Anonymous said...

not work ,, plzzz check it

Suresh Dasari said...

thanks. i updated live demo. Please check it once and let me know if any problem is exists.

Anonymous said...

Thank you , it is working

rahul singh said...

I want to write a character using shift key its not working..

Neeraj said...

i think this not work properly when i enter input as character then enter but when i press shift key then press any alphabetic character then not work......

Irtekaz Ahmed Khan said...

nice working my project in helpful

Atul shukla said...

Thank you so much

Karthik L said...

Thank you so much. I was trying to figure this out for hours. Delete "e.shiftKey ||" for typing Capital letters

Anonymous said...

how to do in asp:textbox?

amardeep dharwan said...

thanqu sir for give a collection of gud n vry useful programes of javascript n Jquery

Anonymous said...

Ur all apps are nice,clear and helpful...............
Keep it up.
thank you

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.