Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

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: ,,
Posted on Tuesday, February 17, 2009 3:54 PM ASP.NET , JavaScript , Tips&Tricks | Back to top


Comments on this post: TextBox that Allows Only Numeric Inputs

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net