JG Vimalan's Blog

It is all about coding!

Allow only numbers in a ASP.NET textbox using JavaScript

Consider you have declared a textbox. Call the JavaScript function as shown below,

<asp:TextBox ID=”demoNumberTextBox” runat=”server” onkeypress=”return NumeralOnlyWithoutDot( event )”

JavaScript: here is the function which allows only numbers in a textbox,

function NumeralOnlyWithoutDot(evt) {
    evt1 = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
   ((evt.which) ? evt.which : 0));
    if ((charCode > 31 && (charCode < 48 || charCode > 57))) {       
        return false;
    return true;

October 16, 2009 - Posted by | JavaScript

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: