Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    text field restriction

    hi.

    i've added this function to restrict inserted values to digits only by using:

    onkeydown="return isFinite(parseInt(String.fromCharCode(event.keyCode)))

    two problems:

    1. i'm restricted only to digits and can't use delete , backspace or arrows.
    2. the numbers on the right of the keybord dont work (the ones with Num Lock)

    any ideas?

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I know this isn't exactly what you're asking, but how about this:

    Code:
    <html>
    <head>
    <script language="javascript">
    function checkNum(object) {
    object.value=object.value.replace(/\D*/g, "");
    }
    </script>
    </head>
    
    <body>
    <input type="text" onkeyup="checkNum(this);">
    </body>
    
    </html>

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    instead of what you have use this:

    onkeyup="this.value=this.value.replace(/\D/,'')"

    that will allow only numbers, as well as tabbing, the arrow keys, and backspacing. You can also use the key pad.

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it's good.
    is there a way to allow arrows also?

  • #5
    New Coder
    Join Date
    Dec 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The code I supplied does allow you to use the arrow keys.

  • #6
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    eranwein:
    Read your PMs.


  •  

    Posting Permissions

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