Introduction:
Here I will explain how to allow only numbers or numeric characters in textbox using JQuery in asp.net.
Description:
In previous posts I explained jQuery Autocomplete textbox with images, jQuery lightbox slideshow, jQuery Create Rounded Corners Textbox, jQuery slideUp, slideDown and slideToggle Example, Password strength jquery plugin examples and many articles relating to JQuery, Asp.net. Now I will explain how to allow only numbers or numeric characters in textbox using JQuery in asp.net.
In previous posts I explained jQuery Autocomplete textbox with images, jQuery lightbox slideshow, jQuery Create Rounded Corners Textbox, jQuery slideUp, slideDown and slideToggle Example, Password strength jquery plugin examples and many articles relating to JQuery, Asp.net. Now I will explain how to allow only numbers or numeric characters in textbox using JQuery in asp.net.
To
restrict user to enter only numbers in textbox we need to write the following
code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery allow only numbers or numeric characters in textbox</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 == 46) || (key >= 35 &&
key <= 40) || (key >= 48 && key <= 57) || (key >= 96
&& key <= 105))) {
e.preventDefault();
}
}
})
})
</script>
</head>
<body>
<form id="form1"
runat="server">
<div>
<asp:TextBox ID="txtNumeric"
runat="server"/>
</div>
</form>
</body>
</html>
|
Live
Demo
To check Live demo try
to enter characters in below textbox
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. |
|||
|
|||
3 comments :
Able to enter charecter
character enter ho rahe he..
fail, it let pass &* and others..
Note: Only a member of this blog may post a comment.