Allow Only Numbers in TextBox in Asp.net
In this tutorial i will explain you, how to allow only numbers in textbox in asp.net.By doing this we will restrict the user to only input numbers in a textbox. We are using JQuery here to solve our requirement.
Demo Page
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>HIghtechnology</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script> <script type="text/javascript"> $(function() { $('#numbers').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="hightechnology" runat="server"> <div> <asp:TextBox ID="numbers" runat="server"/> </div> </form> </body> </html>