input、el-input输入框只能输入正整数(包含或不包含0)
用户投稿 学习笔记 14阅读
一、input 只能输入框只能输入正整数,输入同时禁止了以0开始的数字输入,防止被转化为其他进制的数值。 <!-- 不能输入零时--><input type='text' οninput="value=value.replace(/^(0+)|[^\d]+/g,'')"><!-- 能输入零时--><input type='text' οninput="value=value.replace(/^0+(\d)|[^\d]+/g,'')"> 附:只能输入中文: <input type="text" οninput="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"> 附:只能输入英文: <input type="text" οninput="this.value=this.value.replace(/[^a-zA-Z]/g,'')"> 二、el-input 只能输入框只能输入正整数 <el-input size="small" οnkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="count" maxlength="9"></el-input>data() { return { count: 0 }}
标签: