Java Script function only Integers values in Textbox
In Asp.net Programming some time we need only enter Numeric value in text-boxes like EmpolyeeId, Telephone Number, Mobile Number and so on.
We can use JavaScript for this kind of problem. To allow only numerical values in Asp.net Textboxes.
JavaScript Function:
<script type="text/javascript" language="javascript">
function isNumberKey()
{
if(!(((event.keyCode>=48&&event.keyCode<=57) || (event.keyCode>=96&&event.keyCode<=105))||(event.keyCode==8) || (event.keyCode==9) || (event.keyCode==37) || (event.keyCode==39) || (event.keyCode==46) || (event.keyCode==190)))
event.returnValue=false;
}
<script>
Asp.net:
Calling the above function from Asp.net Textbox control:
<label> Empolyee Id</label>
<asp:TextBox ID="txtEmpID" runat="server" onkeydown="isNumberKey();">
<asp:TextBox>
HTML:
<label> Empolyee Id</label>
<input ID="txtEmpID" onkeydown="isNumberKey();" />
0 comments:
Post a Comment