In this post i have tried to explain how to disallow all other characters then numeric values using javascript .
Using JavaScript
1st Way
Step 1 -
Write the Following JavaScript Code in Scripting area.
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) )
return false;
return true;
}
Step 2-
Now add following textbox code in code-behind on page Load event
TetxBox1.Attributes.Add("onkeypress","return isNumberKey(event)");
2nd Way
<script type="text/javascript">
function IsDecimal(e)
{
var chrCode = (e.which) ? e.which : event.keyCode
return (chrCode > 47 && chrCode < 58) ||
chrCode == 8 ||
chrCode == 45 ||
chrCode == 46 ? true: false;
}
</script>
<input type="text" id="txtDecimal" önkeypress="return IsDecimal(event);" />
0 comments:
Post a Comment