首先,在input中增加onkeyup="clearNoNum(this)"
<script type="text/javascript">
//对输入数字进行校验
function clearNoNum(obj){
obj.value = obj.value.replace(/[^\d.]/g,"");//清除"数字"和"."以外的字符
obj.value = obj.value.replace(/^\./g,"");//验证个字符是数字而不是字符
obj.value = obj.value.replace(/\.{2,}/g,".");//只保留个.清除多余的
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
}
</script>
<script>
this.caseStageInfo.claimedAmountCny=val.replace(/[^\d.]/g,'').replace(/(\d)(\.)(\d*)(\2*)(\d*)/,'$1$2$3$5').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')
</script>
强制英语断行
只能输入整数
<input type="text" value="1"
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,'0')}else{this.value=this.value.replace(/\D/g,'')}" />