当前位置:网站首页>el-input 限制只能输数字
el-input 限制只能输数字
2022-06-30 08:18:00 【_格鲁特宝宝】
el-input 限制只能输数字
方法一:
通过设置type属性:type="number"
<el-input
maxlength="11"
type="number"
v-model="ruleForm.phone"
placeholder="请输入联系方式"
show-word-limit
></el-input>但是这种方式一般会影响样式,不建议使用,如图:

方法二:
通过绑定值限制的方式:v-model.number="ruleForm.phone"
但是这种方式会限制一般的数字,但是会影响 maxlength 属性,并且 e 是可以输入的,一般情况可以使用,严格限制的话不建议
方法三:
建议使用
通过对绑定的 value 值进行正则限制:οnkeyup="value=value.replace(/[^\d]/g, ' ')"
绑定一个onkeyup监听事件, /[^\d]/g 是用来匹配所有非数字内容的正则表达式,将之替换成空字符串,这种方式不会影响任何属性
<el-input
maxlength="11"
v-model="ruleForm.phone"
placeholder="请输入联系方式"
show-word-limit
oninput="value=value.replace(/[^\d]/g,'')"
></el-input>边栏推荐
- More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
- [nvme2.0b 14-7] set features (Part 1)
- tp5设置直接下载文件
- 【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
- Acreems energy efficiency management platform escorts the power safety of high-rise residential areas
- 【NVMe2.0b 14-7】Set Features(上篇)
- MIME类型大全
- This point in JS
- 我们如何拿到自己满意的薪资呢?这些套路还是需要掌握的
- swagger使用
猜你喜欢

Using typera+picgo to realize automatic uploading of markdown document pictures

【NVMe2.0b 14-2】Create/Delete Queue

微信公众号第三方平台开发,零基础入门。想学我教你啊

MySQL cannot connect to the intranet database

Game 280 problem2: minimum operands to turn an array into an alternating array

【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command

End-to-end 3D Point Cloud Instance Segmentation without Detection

鲸探NFT数字臧品系统开发技术分享

Cesium learning notes (V) custom geometry and appearance

Cesium learning notes (VI) particle system
随机推荐
【NVMe2.0b 14】NVMe Admin Command Set
mysql无法连接内网的数据库
【NVMe2.0b 14-2】Create/Delete Queue
【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
Experiment 4 QT
牛客小白月赛52
【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command
【NVMe2.0b 14-4】Directive Send/Receive command
F12 packet capture is used for the whole process analysis of postman interface test
MySQL cannot connect to the intranet database
swagger使用
Miracle Mu server rental selection is real and easy to use, stable and intrusion proof
MIME type Encyclopedia
Niuke Xiaobai month race 52
Using typera+picgo to realize automatic uploading of markdown document pictures
【NVMe2.0b 14-7】Set Features(上篇)
领域驱动下cloud项目中单个服务的示例
微信公众号第三方平台开发,零基础入门。想学我教你啊
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
Experiment 3 remote control