限制输入监听input的input事件

1.只允许输入数字

this.inputValue = this.inputValue.replace(/[^\d]/g, "")

 

2.只允许输入数字和小数点

this.inputValue = this.inputValue.replace(/[^\d.]/g, "")

 

3.只允许输入一个小数点

this.inputValue this.inputValue.replace(/\.{2,}/g"")

 

4.保留两位小数

this.inputValue = this.inputValue.replace( /^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3" )

 

也可以串联使用

this.inputValue this.inputValue.replace(/[^\d.]/g"").replace(/\.{2,}/g"")

posted on 2022-05-13 13:45  双木之下藏倒影  阅读(7442)  评论(0编辑  收藏  举报