zl程序教程

您现在的位置是:首页 >  其它

当前栏目

校验

校验
2023-09-11 14:17:22 时间

参考

一、input
只能输入框只能输入正整数,输入同时禁止了以0开始的数字输入,防止被转化为其他进制的数值。
<!-- 不能输入零时-->
<input type='text' οninput="value=value.replace(/^(0+)|[^\d]+/g,'')">

<!-- 能输入零时-->
<input type='text' οninput="value=value.replace(/^0+(\d)|[^\d]+/g,'')">
1
2
3
4
5
附:只能输入中文:
<input type="text" οninput="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">
1
附:只能输入英文:
<input type="text" οninput="this.value=this.value.replace(/[^a-zA-Z]/g,'')">
1
二、el-input
只能输入框只能输入正整数
<el-input size="small"
οnkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"
v-model="count"
maxlength="9"></el-input>
data() {
return {
count: 0
}
}