正则表达式
1.只能输入整数【正整数和负整数,0】:
onkeyup="this.value=this.value.match(/^-?[0-9]\d*$/)||this.value.match(/-?/)"
onafterpaste="this.value=this.value.match(/^-?[0-9]\d*$/)||this.value.match(/-?/)"
2.只能输入数字:
onkeyup="if(isNaN(value))execCommand('undo')"
onafterpaste="if(isNaN(value))execCommand('undo')"
3.只能输入正数:
onkeyup = "if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
onafterpaste = "if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"