This simple JavaScript  function validates the TextBox input that allows only numeric values to be entered.


<script type ="text/javascript" language="javascript" >
function ValidateText(i)
{
    if(i.value.length>0)
    {
    i.value = i.value.replace(/[^\d]+/g, '');
    }
}
</script>

In your textbox add the onkeyup event or onkeypress.

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" onkeyup = "javascript:ValidateText(this)"></asp:TextBox>

Note: If you wan't to validate a TextBox that allows negative/positive numeric values with two decimal places then you can refer to this links below:

http://forums.asp.net/p/1323787/2645052.aspx#2645052
http://forums.asp.net/t/1356834.aspx

Technorati Tags: ,,