Allow only number in TextBox
Allow only number in TextBox
in asp.net using java script
first Add this java script between head portion in aspx page
<script type=”text/javascript”>
function ValidateNmber(obj, evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
/*First decimal allowed*/
if (charCode == 46 && isDecimal) {
isDecimal = false;
return true;
}
/*Dont allow more*/
else if (charCode == 46 && !isDecimal) {
return false;
}
if (charCode > 31 && (charCode < 48 || charCode > 57) || !isSubmit) {
return false;
}
else {
isDecimal = true;
return true;
}
}
</script>
2) after successfully implement java script, add below coding in your text box page.
<div>
Enter Number: <asp:TextBox ID=”TextBox1″ runat=”server” onkeypress =”javascript:return ValidateNumber(this,event);”></asp:TextBox>
</div>