正则只能输入数字与正数带两位小数
作者:互联网
function num(obj){
obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和".“以外的字符
obj.value = obj.value.replace(/^0/g, “”);//(/^./g,”"); //验证第一个字符是数字
obj.value = obj.value.replace(/.{2,}/g,"."); //只保留第一个, 清除多余的
obj.value = obj.value.replace(".","KaTeX parse error: Expected 'EOF', got '#' at position 1: #̲").replace(/./g,"").replace("KaTeX parse error: Expected 'EOF', got '#' at position 1: #̲",".");
obj.value = obj.value.replace(/^(-)(\d+).(\d\d).$/,’$1$2.$3’); //只能输入两个小数
}
标签:obj,value,replace,parse,正则,KaTeX,Expected,正数,小数 来源: https://blog.csdn.net/weixin_38808724/article/details/104396465