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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Allowing numeric numbers only

    I have a text field that requires a users extension and only 0-9 is acceptable with no alpha characters allowed. How can I do this?

    Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could do something like this -
    http://www.cs.tut.fi/~jkorpela/forms/check2.html

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    <input type="text" onkeyup="if(isNaN(this.value)) { this.value=this.value.substring(0, this.value.length-1) }">

    Edit: Actually, this is probably a better solution than the one I posted above here.

    <html>
    <head>
    <script language="javascript">
    function checkNum(object) {
    object.value=object.value.replace(/\D*/g, "");
    }
    </script>
    </head>

    <body>
    <input type="text" id="usage" onkeyup="checkNum(this);">
    </body>

    </html>
    Last edited by arnyinc; 01-18-2006 at 10:16 PM.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,501
    Thanks
    3
    Thanked 500 Times in 487 Posts
    solution already posted


  •  

    Posting Permissions

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