clearNoNum(value) {
value = value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
this.value = value;
var temp = this.value;
if (temp < 0) {
this.value = "";
return;
}
var posDot = temp.indexOf("."); //返回指定字符在此字符串中第一次出现处的索引
if (posDot < 0) {
//不包含小数点
if (temp.length <= 5) {
return; //小于五位数直接返回
} else {
// this.value.delete(5, 6);//大于五位数就删掉第六位(只会保留五位)
if (temp.length > 5) {
this.value = temp.substring(0, 5);
}
return;
}
}
//走到这有小数点
if (posDot > 5) {
// edt.delete(5, 6);//大于五位数就删掉第六位(只会保留五位)
if (temp.length > 5) {
this.value = temp.substring(0, 5);
}
return;
}
value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
value = value
.replace(".", "$#$")
.replace(/\./g, "")
.replace("$#$", ".");
value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
this.value = value;
},