做两位小数校验
简单记录一下
input(val){
this.value = this.value+''
this.value = this.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
this.value = this.value.replace(/^\./g,""); //验证第一个字符是数字而不是.
this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");//只允许输入一个小数点
this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
},