Simple Example of js method data verification, js verification instance

Source: Internet
Author: User

Simple Example of js method data verification, js verification instance

Example:

// The input tag can only be a positive number <input onkeyup = "this. value = this. value. replace (/[^ 1-9]/g, '')"> // only a positive integer function CheckNum (thisobj) {if (thisobj. value = "0") {} else {var firstNum = thisobj. value. toString (). substring (0, 1); if (thisobj. value. length = 1) {thisobj. value = thisobj. value. replace (/[^ 0-9]/g, '');} else if (thisobj. value. length> 1 & firstNum = "0") {thisobj. value = "0";} else if (thisobj. value. length> 1) {thisobj. value = thisobj. value. replace (/[^ 0-9]/g, '') }}// you can only enter the amount function ClearNoNum (obj) {if (obj. value = "0") {} else {var firstNum = obj. value. toString (). substring (0, 1); if (obj. value. length> 1 & firstNum = "0") {obj. value = "0" ;}}// replace all non-numeric values first, except numbers and. obj. value = obj. value. replace (/[^ \ d.] /g, ""); // The first one must be a number instead of a number. obj. value = obj. value. replace (/^ \. /g, ""); // ensure that only one exists. no. obj. value = obj. value. replace (/\. {2,}/g ,". "); // guarantee. only appears once, but cannot appear more than twice. value = obj. value. replace (". "," $ # $ "). replace (/\. /g ,""). replace ("$ # $ ",". ");}

The simple example of the above js method data verification is all the content shared by Alibaba Cloud xiaobian. I hope to give you a reference and support for the help house.

Related Article

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.