当前位置:网站首页>小程序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
},
}边栏推荐
猜你喜欢
随机推荐
邮件管理 过滤邮件
el-autocomplete use
Error correction notes for the book Image Processing, Analysis and Machine Vision
Next-Generation Parsing Technology - Cloud Parsing
亚马逊美国站:马术头盔CPC认证标准要求
MySQL的主从模式搭建
Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive
Network Troubleshooting Basics - Study Notes
Passing parameters in multiple threads
Q 2020, the latest senior interview Laya soul, do you know?
Difference between link and @improt
自营商城提高用户留存小技巧,商城对接小游戏分享
数组&的运算
Configuration of routers and static routes
js判断文字是否超过区域
系统基础-学习笔记(一些命令记录)
图像处理、分析与机器视觉一书纠错笔记
Seven Ways to Center a Box Horizontally and Vertically
[ingress]-ingress exposes services using tcp port
NB-IOT智能云家具项目系列实站









