JS verification can only enter digital program code

Source: Internet
Author: User

Number in our expression has, positive, negative, decimal, I will introduce you to the following.

1. Text box can only enter a numeric code (decimal point can not enter)

The code is as follows Copy Code

<input onkeyup= "This.value=this.value.replace (/d/g,") "Onafterpaste=" This.value=this.value.replace (/D/g, "") " >

2. Only numbers can be entered and the decimal point may be lost.

The code is as follows Copy Code

<input onkeyup= "if (isNaN (value)) ExecCommand (' Undo ') ' onafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') >
<input name=txt1 onchange= "if (/d/.test (this.value)) {alert (' can only enter numbers '); this.value= ';} ' >

3. Negative Certification

  code is as follows copy code

var flag3 = false;
var planallocation = document.getelementsbyname (' planallocation_xx '); //Plan allocation number
var size1 = planallocation . length;
var exp   =  /^ (-?[ 1-9][0-9]*|0) $/;
//To determine the number of plans entered is an exception character
for (var i=0;i<size1;i++)
{
    if (!exp.test (planallocation[i). Value)
    {
    flag3 = true;
    break;
   }
}

if (flag3==true)
{
Alert ("Please enter Integer, cannot contain special characters");
return false;
}


For more details see: http://www.111cn.net/wy/js-ajax/35726.htm

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.