JavaScript limits can only enter numbers and decimals

Source: Internet
Author: User

Web page effects limit you can only enter numbers and decimals
You can only enter a number, and the range is between 0.0~999.9, a decimal can be entered only one digit, the integer up to 3 digits, allowing no decimal.
Requirements: An input box, you can only enter a number or decimal point, other characters do not display;
The integer part is entered up to three bits;
The decimal part is entered at most one digit.

1: 2:    3: <script language=javascript>   1:     2:function limite (object) & nbsp;  3: {   4:     if (isNaN (object.value))         5:     {       6:          dosubstring (object);   7:    }   8:     else   9:     {  10:         var index = Object.value.indexof ('. ');   11:         if (Index > 0)   12:          {  13:             if ( Object.value.length > Index + 2)   14:                  dosubstring (object);  15:&NBSP;&NBSP;&Nbsp;     }  16:         else  17:          {  18:              var ivalue = parseint (obaject.value);  19:              if (Ivalue < 0 | | ivalue >=1000)   20:                  dosubstring (object);  21:         }  22:    } :}  24:function dosubstring (object )  : {  26:     object.value=object.value.substring (0,object.value.length-1);  :}</script>
4: 5:
6: <body>
7: <input onpropertychange= "Limite (this)" Maxlength= "5" name= "Amount"/>
8: </body>
9:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.