当前位置:网站首页>小程序input框不允许输入负数
小程序input框不允许输入负数
2022-08-05 05:29:00 【weixin_43923808】
小程序版
<template>
<view>
<input placeholder="请输入金额" type="digit" placeholder-class="phcolor" value="{
{amount}}" data-key="mobile" @input="handleInput"></input>
</view>
</template>
methods = {
handleInput(e) {
var obj = e.detail.value
obj = obj.replace(/[^\d.]/g, '') //清除“数字”和“.”以外的字符
obj = obj.replace(/\.{2,}/g, '.') //只保留第一个. 清除多余的
obj = obj
.replace('.', '$#$')
.replace(/\./g, '')
.replace('$#$', '.')
obj = obj.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') //只能输入两个小数
if (obj.indexOf('.') < 0 && obj != '') {
//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
obj = parseFloat(obj)
}
this.amount = obj
},
}
边栏推荐
猜你喜欢
LaTeX image captioning text column automatic line wrapping
Passing parameters in multiple threads
BIO,NIO,AIO实践学习笔记(便于理解理论)
Q 2020, the latest senior interview Laya soul, do you know?
如何将.asd恢复为Word文档
After docker is deployed, mysql cannot connect
摆脱极域软件的限制
NAT experiment
el-progress implements different colors of the progress bar
单片机原理与应用复习
随机推荐
深入分析若依数据权限@datascope (注解+AOP+动态sql拼接) 【循序渐进,附分析过程】
Alibaba Cloud Video on Demand
LeetCode practice and self-comprehension record (1)
自营商城提高用户留存小技巧,商城对接小游戏分享
Transformer详细解读与预测实例记录
VSCode编写OpenCV
D39_Eulerian Angles and Quaternions
Matplotlib绘图笔记
LaTeX uses frame to make PPT pictures without labels
## 简讲protobuf-从原理到使用
transport layer protocol
花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口
document.querySelector() method
document.querySelector()方法
Successful indie developers deal with failure & imposters
What is the website ICP record?
selenium learning
Email management Filter emails
DisabledDate date picker datePicker
D39_Vector