Click here to Skip to main content
12,635,269 members (22,828 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7.3K views
1 bookmarked
Posted

Allow only Numeric values in ASP Text box control using JavaScript

, 11 Feb 2012 CPOL
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...

Pro
Pro

Comments and Discussions

 
Generali tried this code. But this has an error If i enter 1.2.1.1 ... Pin
Member 847608323-Feb-12 2:37
memberMember 847608323-Feb-12 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.161208.2 | Last Updated 11 Feb 2012
Article Copyright 2012 by Emad Mokhtar
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid