Use jquery implementation to verify whether the input is a number, decimal, containing a few decimal _jquery

Source: Internet
Author: User

1, the authentication method Validationnumber (E, num) e is the label object, and Num stands for the number of decimal digits.

function Validationnumber (e, num) {
      var regu =/^[0-9]+\.? [0-9]*$/;
      if (E.value!= "") {
        if (!regu.test (E.value)) {
          alert ("Please enter 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, verify the integer

<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 a 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. Keep two decimal digits

<asp:textbox id= "Txtstdyr" name= "Txtstdyr" runat= "Server" height= "16px" width= "98px" font-size= "9pt" 
   CssClass = "Edittextbox" onpropertychange= "Validationnumber (this,2)" ></asp:TextBox>

5. Keep three decimal digits

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

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

Above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if there are questions you can message exchange, but also hope that a lot of support cloud Habitat community!

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.