当前位置:网站首页>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
- BIO, NIO, AIO practical study notes (easy to understand theory)
- System basics - study notes (some command records)
- config.js相关配置汇总
- Network Protocol Fundamentals - Study Notes
- Q 2020, the latest senior interview Laya soul, do you know?
- vscode notes
- 字体样式及其分类
- 农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1
- LeetCode practice and self-comprehension record (1)
猜你喜欢

农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1

One-arm routing experiment and three-layer switch experiment

Vim tutorial: vimtutor

Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive

The hook of the operation of the selenium module

单片机期末复习大题

transport layer protocol

Cocos Creator Mini Game Case "Stick Soldier"

The 25 best free games on mobile in 2020

Error correction notes for the book Image Processing, Analysis and Machine Vision
随机推荐
NB-IOT智能云家具项目系列实站
Transformer interprets and predicts instance records in detail
超简单的白鹭egret项目添加图片详细教程
Seven Ways to Center a Box Horizontally and Vertically
滚动条问题,未解决
无法导入torchvision.io.read_image
vscode笔记
单片机期末复习大题
transport layer protocol
Q 2020, the latest senior interview Laya soul, do you know?
深入分析若依数据权限@datascope (注解+AOP+动态sql拼接) 【循序渐进,附分析过程】
Email management Filter emails
Passing parameters in multiple threads
Quick Start to Drools Rule Engine (1)
数组&的运算
记录vue-页面缓存问题
Detailed explanation of the construction process of Nacos cluster
Cocos Creator Mini Game Case "Stick Soldier"
NACOS配置中心设置配置文件
浏览器兼容汇总