Verifies whether the input is a number, a decimal, and contains a few decimals reserved

Source: Internet
Author: User

1. Verification Method Validationnumber (E, NUM) e represents the Label object, and Num represents the number of decimal digits reserved

function Validationnumber (e, num) {varRegu =/^[0-9]+\.? [0-9]*$/; if(E.value! ="") {                if(!regu.test (E.value)) {Alert ("Please enter the correct number"); E.value= E.value.substring (0, E.value.length-1);                E.focus (); } Else {                    if(num = =0) {                        if(E.value.indexof ('.') >-1) {E.value= E.value.substring (0, E.value.length-1);                        E.focus (); }                    }                    if(E.value.indexof ('.') >-1) {                        if(E.value.split ('.')[1].length >num) {E.value= E.value.substring (0, E.value.length-1);                        E.focus (); }                    }                }            }        }

2. Verifying integers

<asp:textbox id="txtng"Name="txtng"runat="Server"height="16px"Width="98px"Font-size="9pt"CssClass="Edittextbox"Onpropertychange="Validationnumber (this,0)"></asp:TextBox>

3. Keep One decimal

<asp:textbox id="Txtchglinecost"Name="Txtchglinecost"runat="Server"height="16px" Width="98px"Font-size="9pt" 
cssclass="Edittextbox"Onpropertychange="Validationnumber (this,1)"></asp:TextBox>

4. Retain two decimal places

<asp:textbox id="Txtstdyr"Name="Txtstdyr"runat="Server"height="16px"Width="98px" Font-size="9pt" 
cssclass="Edittextbox"Onpropertychange="Validationnumber (this,2)"></asp:TextBox>

5. Retain three decimal places

You only need to change the second parameter in the Validationnumber (this,3) method to 3.

Keep Four decimal places, keep five decimal places, etc...

Verify that the input is numeric, fractional, and contains several decimals reserved

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.