当前位置:网站首页>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>边栏推荐
- unity 将Text批量替换为TextMeshProUGUI
- What is Alibaba Cloud Express Beauty Station?
- DisabledDate date picker datePicker
- NB-IOT智能云家具项目系列实站
- Browser Storage for H5
- The 25 best free games on mobile in 2020
- DevOps - Understanding Learning
- 格式化代码缩进的小技巧
- 浏览器兼容汇总
- Dry!Teach you to use industrial raspberries pie combining CODESYS configuration EtherCAT master station
猜你喜欢

Some basic method records of commonly used languages in LeetCode

VRRP overview and experiment

el-progress implements different colors of the progress bar
![In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]](/img/b5/03f55bb9058c08a48eae368233376c.png)
In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]

DevOps-了解学习

邮件管理 过滤邮件

transport layer protocol

【FAQ】CCAPI Compatible EOS Camera List (Updated in August 2022)

Quick Start to Drools Rule Engine (1)

config.js related configuration summary
随机推荐
The future of cloud gaming
Met with the browser page
txt文件英语单词词频统计
Difference between link and @improt
VSCode编写OpenCV
LaTeX笔记
ev加密视频转换成MP4格式,亲测可用
LeetCode练习及自己理解记录(1)
Get the network input dimensions of the pretrained model
reduce()方法的学习和整理
wc, grep, tar, vi/vim
Nacos集群的搭建过程详解
document.querySelector() method
LaTeX使用frame制作PPT图片没有标号
LaTeX image captioning text column automatic line wrapping
## 简讲protobuf-从原理到使用
Transformer详细解读与预测实例记录
指针常量与常量指针 巧记
Vim tutorial: vimtutor
D46_Force applied to rigid body