Geeks With Blogs


Microsoft MVP


Moderator at CodeASP.NET

Quiz Master

free counters
Free counters
Added on January 19,2012

Follow Me @vmsdurano

A bit About Me

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)
    i.value = i.value.replace(/[^\d]+/g, '');

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:

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: