Results 1 to 5 of 5

Thread: allow only numeric data including decimal

  1. #1
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default allow only numeric data including decimal

    the user cannot type letters or special characters into the input field.
    could you please help me?

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

  3. #3
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Code:
    <input type="text" onkeyup="this.value=!this.value.match(/[\d.]$/)?this.value.substring(0,this.value.length-1):this.value;">
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    for +ve and -ve floating point

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    function zxcFloat(obj){
     obj.value=obj.value.replace(/[^-?\d\.]/g,'');
     obj.value=parseFloat(obj.value);
    }
    /*]]>*/
    </script>
    <body>
    <input name="" onblur="zxcFloat(this)"/>
    </body>
    
    </html>

  5. #5
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    if the user press any letter/special characters, it will not appear in the textbox.
    thanks

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
  •