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