Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Allow only Numeric values in ASP Text box control using JavaScript

, 11 Feb 2012
Rate this:
Please Sign up or sign in to vote.
$(document).re...
$(document).ready(function () {
    $('#TextboxID').keydown(function (event) {
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9) {
            // let it happen, don't do anything
        }
        else {
            // Ensure that it is a number and stop the keypress
            if ((event.keyCode >= 48 && event.keyCode <= 57) || 
                  (event.keyCode >= 96 && event.keyCode <= 105) || 
                   event.keyCode == 190) {
 
            }
            else {
                event.preventDefault();
            }
        }
    });
});

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Emad Mokhtar
Software Developer
Egypt Egypt
No Biography provided
Follow on   Twitter

Comments and Discussions

 
Generali tried this code. But this has an error If i enter 1.2.1.1 ... PinmemberMember 847608323-Feb-12 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 11 Feb 2012
Article Copyright 2012 by Emad Mokhtar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid