SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot unformatik's Avatar
    Join Date
    Aug 2007
    Location
    216/GMT+1
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how to restrict inputs text with only numbers

    Hi all,
    Please I want to restrict Input fields with out lettre special caracter and 0 (zero).
    how to do that in pure html or with Java scripts.
    Thanks

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Move to JavaScript, since you can't do this with HTML.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Zealot unformatik's Avatar
    Join Date
    Aug 2007
    Location
    216/GMT+1
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't find a solution with JS

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works in DOM2-compliant browsers, so you'll have to adapt a bit to make it work in IE, but it should set you on the right path.

    Code JavaScript:
    document.getElementById("whatever").addEventListener(
        "keypress",
        function (e) {
            var ch = e.which;
            if (ch > 31 && (ch < 49 || ch > 57)) {
                e.preventDefault();
                e.stopPropagation();
            }
        },
        false);
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Zealot unformatik's Avatar
    Join Date
    Aug 2007
    Location
    216/GMT+1
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    i'm too late, I'm sorry thank you for the code !

  6. #6
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    This works in DOM2-compliant browsers, so you'll have to adapt a bit to make it work in IE, but it should set you on the right path.

    Code JavaScript:
    document.getElementById("whatever").addEventListener(
        "keypress",
        function (e) {
            var ch = e.which;
            if (ch > 31 && (ch < 49 || ch > 57)) {
                e.preventDefault();
                e.stopPropagation();
            }
        },
        false);
    Nice one.
    mmj


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •