Create Numerical TextBox in ASP.Net using Javascript

– Create Numerical TextBox in ASP.Net

– Create Numerical TextBox in using Javascript

In this post we will learn How to create numeric TextBox in ASP.Net using Javascript.

Numeric Textbox allow user to enter only 0-9 digit in textbox control in asp.net.

Here, we take Example of Mobile No. We create Textbox which is allow to enter only 10 Digit no.

We will solve this textbox example using javascript in asp.net

Write below javascript  code in Head tag :-

<head runat=”server”>
<title>Mobile Validate using Javascript</title>
<script type=”text/javascript”>

function ValidMobile(val)
{
var valuee = (val.which) ? val.which : val.keyCode;
var val = document.getElementById(‘txtMobile’);

if (!(valuee==8 || valuee==46)&&(valuee < 48 || valuee > 57))
{  return false;
}
else
{
if (val.value.length <10)
{
return true;
}
else
{
return false;
}
}
}
</script>
</head>

– Write below code in Body for Design page  :-

<body>
<form id=”form1″ runat=”server”>
<div>
&nbsp;
</div>
<table style=”z-index: 100; left: 456px; width: 256px; position: absolute; top: 144px”>
<tr>
<td style=”width: 100px”>
<strong>Allow only Mobile No. in TextBox&nbsp; </strong>
</td>
</tr>
<tr>
<td style=”width: 100px”>
<asp:TextBox ID=”txtMobile” runat=”server” onkeypress=”return ValidMobile(event)”></asp:TextBox></td>
</tr>
</table>
</form>
</body>

The Out Put of asp.net controls example like :

Create Numeric TextBox using Javascript in asp.net
Create Numeric TextBox using Javascript in asp.net

I hope this Create Numeric TextBox using Javascript in asp.net will help you….

Leave a Reply

Your email address will not be published. Required fields are marked *