当前位置:网站首页>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>
边栏推荐
- config.js相关配置汇总
- Next-Generation Parsing Technology - Cloud Parsing
- H5开发调试-Fiddler手机抓包
- 淘宝宝贝页面制作
- 网络协议基础-学习笔记
- Collision, character controller, Cloth components (cloth), joints in the Unity physics engine
- GetEnumerator method and MoveNext and Reset methods in Unity
- Browser Storage for H5
- D39_ coordinate transformation
- wc, grep, tar, vi/vim
猜你喜欢
设置文本向两边居中展示
GetEnumerator method and MoveNext and Reset methods in Unity
config.js related configuration summary
Error correction notes for the book Image Processing, Analysis and Machine Vision
花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口
The 25 best free games on mobile in 2020
UI刘海屏适配方式
lingo入门——河北省第三届研究生建模竞赛B题
NACOS配置中心设置配置文件
滚动条问题,未解决
随机推荐
Collection of error records (write down when you encounter them)
系统基础-学习笔记(一些命令记录)
超简单的白鹭egret项目添加图片详细教程
滚动条问题,未解决
多用户商城多商户B2B2C拼团砍价秒杀支持小程序H5+APP全开源
LaTeX 图片加标题 文本分栏自动换行
【内推】新相微电子
数组&的运算
七夕!专属于程序员的浪漫表白
[ingress]-ingress exposes services using tcp port
前置++和后置++的区别
【8】Docker中部署Redis
Detailed explanation of ten solutions across domains (summary)
Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
盒子模型小练习
VS Code私有服务器部署(私有化)
cs231n learning record
【FAQ】什么是 Canon CCAPI
numpy.random usage documentation
The future of cloud gaming