Click here to Skip to main content
11,709,955 members (67,860 online)
Click here to Skip to main content

Tagged as

Allow only Numeric values in ASP Text box control using JavaScript

, 11 Feb 2012 CPOL 5.6K 1
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

You may also be interested in...

Comments and Discussions

 
Generali tried this code. But this has an error If i enter 1.2.1.1 ... Pin
Member 847608323-Feb-12 1:37
memberMember 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 | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 11 Feb 2012
Article Copyright 2012 by Emad Mokhtar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid