当前位置:网站首页>JS控制只能输入数字并且最多允许小数点两位
JS控制只能输入数字并且最多允许小数点两位
2022-08-05 05:29:00 【weixin_43923808】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="text" name="je" onblur="clearNoNum(this)"/>元
<script type="text/javascript">
function clearNoNum(obj) {
obj.value = obj.value.replace(/[^\d.]/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');//只能输入两个小数
if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
obj.value = parseFloat(obj.value);
}
if (!obj.value || obj.value == '0' || obj.value == '0.0' || obj.value == '0.00') {
alert('退款金额不能为空');
return;
}
// 正常得话继续调后端接口
}
</script>
</body>
</html>边栏推荐
- Passing parameters in multiple threads
- HelloWorld
- Pytorch分布式并行处理
- input detailed file upload
- The hook of the operation of the selenium module
- DisabledDate date picker datePicker
- Detailed explanation of the construction process of Nacos cluster
- UI刘海屏适配方式
- Mina's long and short connections
- The size of the screen adaptation
猜你喜欢
随机推荐
NACOS配置中心设置配置文件
DevOps process demo (practical record)
D46_Force applied to rigid body
What is Alibaba Cloud Express Beauty Station?
Detailed explanation of the construction process of Nacos cluster
LaTeX uses frame to make PPT pictures without labels
LaTeX 图片加标题 文本分栏自动换行
NACOS Configuration Center Settings Profile
Nacos集群的搭建过程详解
vs2017关于函数命名方面的注意事项
前置++和后置++的区别
Transformer详细解读与预测实例记录
After docker is deployed, mysql cannot connect
Successful indie developers deal with failure & imposters
【MyCat简单介绍】
LeetCode刷题记录(2)
Nacos集群搭建
D39_Eulerian Angles and Quaternions
浏览器兼容汇总
js判断文字是否超过区域








