限制输入类型
... 2022-11-17 Less than 1 minute
# 限制输入类型
// 使用方法
<el-input @keyup="btKeyUp"></el-input>
// 限制特殊符号
function btKeyUp(e) {
e.target.value = e.target.value.replace(
/[`~@#$%^&_()\_\-+=<>:"{}|\/;'\\[\]·~!@#¥%……&_()——\-+={}|《》:“”【】、;‘’]/g,
""
)
}
// 限制字母中文数字
function btKeyUp2(e) {
e.target.value = e.target.value.replace(/[^a-za-z0-9]/g, "")
}
// 限制整数和小数
function btKeyUp3(e) {
e.target.value = e.target.value.match(/^\d*(\.?\d{0,2})/g)[0] || null;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21