当前位置:网站首页>el-input can only input integers (including positive numbers, negative numbers, 0) or only integers (including positive numbers, negative numbers, 0) and decimals
el-input can only input integers (including positive numbers, negative numbers, 0) or only integers (including positive numbers, negative numbers, 0) and decimals
2022-07-30 19:41:00 【bsegebr】
el-inputLabels are even usedtype=number或者v-model.number属性,It may not be exactly what we want,So write the regular expression manually below
<el-input v-model="height" placeholder="请输入" @input="handleEdit" />
el-input 只能输入正整数(包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^d]/g, ""); // 只能输入数字
value = value.replace(/^0+(d)/, "$1"); // 第一位0开头,0followed by numbers,则过滤掉,Take the number that follows
value = value.replace(/(d{15})d*/, '$1') // 最多保留15位整数
this.height = value
}
el-input 只能输入正整数(不包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/^(0+)|[^d]+/g,''); // 以0start or enter a non-numeric,会被替换成空
value = value.replace(/(d{15})d*/, '$1') // 最多保留15位整数
this.height = value
}
el-input Only negative integers can be entered(包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^-d]/g, ""); // 只能输入-和数字
value = value.replace(/^[1-9]/g, ""); // 不能以1-9开头
value = value.replace(/-{2,}/g, "-"); // -只能保留一个
value = value.replace(/(d)-/g, "$1"); // Numbers cannot be followed-,Can't appear similar-11-2,12-,11-23
value = value.replace(/-(0+)/g, "0"); // 不能出现-0,-001,-0001类似
value = value.replace(/^0+(d)/, "0"); // 第一位0开头,0followed by numbers,则过滤掉,取0
value = value.replace(/(-d{15})d*/, '$1') // 最多保留15位整数
this.height = value
}
el-input Only negative integers can be entered(不包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^-d]/g, ""); // 只能输入-和数字
value = value.replace(/^d/g, ""); // 不能以数字开头
value = value.replace(/-{2,}/g, "-"); // -只能保留一个
value = value.replace(/(d)-/g, "$1"); // Numbers cannot be followed-,Can't appear similar-11-2,12-,11-23
value = value.replace(/(-)0+/g, "$1"); // 不能出现-0,-001,-0001类似
value = value.replace(/(-d{15})d*/, '$1') // 最多保留15位整数
this.height = value
}
el-input 只能输入整数(包括正整数、负整数、0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^-d]/g, ""); // 只能输入-和数字
value = value.replace(/-{2,}/g, "-"); // -只能保留一个
value = value.replace(/(d)-/g, "$1"); // Numbers cannot be followed-,Can't appear similar-11-2,12-,11-23
value = value.replace(/-(0+)/g, "0"); // 不能出现-0,-001,-0001类似
value = value.replace(/^0+(d)/, "$1"); // 第一位0开头,0followed by numbers,则过滤掉,Take the number that follows
value = value.replace(/(-?d{15})d*/, '$1') // 最多保留15位整数
this.height = value
}
el-input Only positive decimals can be entered(包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^d.]/g, '') // 只能输入数字和.
value = value.replace(/^./g, '') //第一个字符不能是.
value = value.replace(/.{2,}/g, '.') // 不能连续输入.
value = value.replace(/(.d+)./g, '$1') // .No further input can be made later.
value = value.replace(/^0+(d)/, '$1') // 第一位0开头,0followed by numbers,则过滤掉,Take the number that follows
value = value.replace(/(d{15})d*/, '$1') // 最多保留15位整数
value = value.replace(/(.d{2})d*/, '$1')// 最多保留2位小数
this.height = value
}
el-input Only negative decimals can be entered(包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^-d.]/g, ""); // 只能输入-and numbers and.
value = value.replace(/^[^-0]/g, ""); // 只能-和0开头
value = value.replace(/-{2,}/g, "-"); // 不能连续输入-
value = value.replace(/(-)./g, "$1"); // -cannot be entered later.
value = value.replace(/.{2,}/g, "."); // 不能连续输入.
value = value.replace(/(.d+)./g, "$1"); // .No further input can be made later.
value = value.replace(/(d+|.)-/g, "$1"); // 数字和.后面不能接-,Can't appear similar11-, 12.-
value = value.replace(/(-)0+(d+)/g, '$1$2') // 不能出现-01,-02类似
value = value.replace(/^0+(d|.)/, "0"); // 第一位0开头,0followed by a number or.,则过滤掉,取0
value = value.replace(/(d{15})d*/, '$1') // 最多保留15位整数
value = value.replace(/(.d{2})d*/, '$1')// 最多保留2位小数
this.height = value
}
el-input Only negative decimals can be entered(不包括0)
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^-d.]/g, ""); // 只能输入-and numbers and.
value = value.replace(/^[^-]/g, ""); // 只能-开头
value = value.replace(/-{2,}/g, "-"); // 不能连续输入-
value = value.replace(/(-)./g, "$1"); // -cannot be entered later.
value = value.replace(/.{2,}/g, "."); // 不能连续输入.
value = value.replace(/(.d+)./g, "$1"); // .No further input can be made later.
value = value.replace(/(d+|.)-/g, "$1"); // 数字和.后面不能接-,Can't appear similar11-, 12.-
value = value.replace(/(-)0+(d+)/g, '$1$2') // 不能出现-01,-02类似
value = value.replace(/(d{15})d*/, '$1') // 最多保留15位整数
value = value.replace(/(.d{2})d*/, '$1')// 最多保留2位小数
this.height = value
}
el-input 输入整数(包括正数、负数、0)和小数,保留15位整数和2位小数
// 在 Input 值改变时触发
handleEdit(e) {
let value = e.replace(/[^-d.]/g, '') // 只能输入.和-和数字
value = value.replace(/^./g, '') //第一个字符不能是.
value = value.replace(/.{2,}/g, '.') // 不能连续输入.
value = value.replace(/(.d+)./g, '$1') // .No further input can be made later.
value = value.replace(/(-)./g, '$1') // -cannot be entered later.
value = value.replace(/-{2,}/g, '-') // -只能保留一个
value = value.replace(/(d+|.)-/g, '$1') // 数字和.后面不能接-,Can't appear similar11-, 12.-
value = value.replace(/-(0){2,}/g, "$1") // 不能出现-00,-001,-0001类似
value = value.replace(/(-)0+(d+)/g, '$1$2') // 不能出现-01,-02类似
value = value.replace(/^0+(d)/, '$1') // 第一位0开头,0followed by numbers,则过滤掉,Take the number that follows
value = value.replace(/(d{15})d*/, '$1') // 最多保留15位整数
value = value.replace(/(.d{2})d*/, '$1')// 最多保留2位小数
this.height= value
}
$1Indicates that match the content in the first parenthesis,$2Indicates what matches the second parenthesis,比如
value = value.replace(/(-)./g, '$1') // 输入框输入-.就会替换成-
value = value.replace(/(-)(0{2,})/g, '$1$2') // 输入-00,-000,就会替换成-0
It's a bit complicated to write,没办法,Just getting started with regular expressions.如果配合el-input标签的type=number或者v-model.number属性,The regular expression part may not have to be written so much and is complicated.If there is a simpler way, please leave a message in the comment area
附上:
正则表达式 学习网址1
正则表达式 学习网址2
Regular expression online test URL
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在.深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小.自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前.因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担.添加下方名片,即可获取全套学习资料哦
边栏推荐
- 已删除
- [PyTorchVideo Tutorial 01] Quickly implement video action recognition
- After watching "Second Uncle", I was even more internalized
- MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
- MySQL six-pulse sword, SQL customs clearance summary
- win2003下FTP服务器如何搭建
- MySQl数据库————DQL数据查询语言
- 【刷题篇】计算质数
- 来了!东方甄选为龙江农产品直播带货
- Trial writing C language sanbang
猜你喜欢
青蛙跳台阶(递归和非递归)-------小乐乐走台阶
MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
LeetCode 0952.按公因数计算最大组件大小:建图 / 并查集
阿里面试官:给我描述一下缓存击穿的现象,并说说你的解决思路?
The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
MySQl数据库————DQL数据查询语言
Golang logging library zerolog use record
Database Tuning - Database Tuning
[PyTorchVideo Tutorial 01] Quickly implement video action recognition
随机推荐
【MindSpore1.2.0-rc1产品】num_workers问题
MySQL复制表结构、表数据的方法
Vulkan开启特征(feature)的正确姿势
055 c# print
【flink】报错整理 Could not instantiate the executor. Make sure a planner module is on the classpath
Download and installation of the latest version of MySQL 8.0 under Linux (detailed steps)
LeetCode 0952.按公因数计算最大组件大小:建图 / 并查集
Witness the magical awakening of the mini world in HUAWEI CLOUD
Zabbix 5.0 Monitoring Tutorial (1)
第一次进入小程序判断
【私人系列】日常PHP遇到的各种稀奇古怪的问题
牛客刷题系列之进阶版(搜索旋转排序数组,链表内指定区间反转)
MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远
HCIP --- 企业网的三层架构
数据库索引:索引并不是万能药
mysql8 installation under linux
The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
Range.CopyFromRecordset method (Excel)
【科普】无线电波怎样传送信息?
MindSpore:【JupyterLab】查看数据时报错