Allow only numbers or decimal in textbox
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RNDWithNumbers.aspx.cs"
Inherits="TabFormWebApp.RNDWithNumbers" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Script/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function isNumberWithDecimalKey(evt, obj) {
var charCode = (evt.which) ? evt.which : event.keyCode
var value = obj.value;
var dotcontains = value.indexOf(".") != -1;
if (dotcontains)
if (charCode == 46) return false;
if (charCode == 46) return true;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
</script>
</head>
<body>
<form id="frm" runat="server">
<table>
<tr>
<td>
Only Number
</td>
<td>
<input type="text" id="txtAllowNumber" onkeypress="return isNumber(event)" />
</td>
</tr>
<tr>
<td>
Only Number With Decimal
</td>
<td>
<input type="text" id="txtAllowNumberWithDecimal" onkeypress="return isNumberWithDecimalKey(event,this)" />
</td>
</tr>
</table>
<br />
</form>
</body>
</html>
Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog on. .Net Online course
ReplyDeleteThanks a lot for sharing such a good source with all, i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
Allowing only numbers or decimals in a textbox is a time-saving. It simplifies data entry, ensuring that users provide accurate numerical inputs without additional validations. The App Download It is feature that improves data quality.
ReplyDelete