InputRegZen.vue 正则Input 限制输入框输入内容
核心内容 已经 perfect,没有用外库,原生完成 用的 iview的Input组件 封装
// InputRegZen.vue
<template>
<div>
<Input v-model="currentValue"
ref="inputRef"
:maxlength="maxlength"
:placeholder="placeholder"
:disabled="disabled"
@input="inputHandle" />
</div>
</template>
<script>
export default {
name: 'InputRegZen',
props: {
regStr: {
type: String,
default: "中文数字字母_"
},
maxlength: {
type: Number,
default: 30,
},
placeholder: {
type: String,
default: ''
},
disabled: {
type: Boolean,
default: false,
},
value: {
type: String,
default: ''
},
},
components: {},
data () {
return {
currentValue: this.value.toString(),
}
},
watch: {
value: function (val) {
this.currentValue = this.value.toString()
},
},
computed: {},
methods: {
inputHandle (val) {
if (this.clearSpot(val) !== val) { // 有非法字符
const diff = this.getDiff(val, this.clearSpot(val))
this.$nextTick(() => {
this.currentValue = this.value
this.$nextTick(() => {
this.$refs.inputRef.$refs.input.setSelectionRange(diff, diff)
})
})
} else { // 全部合法
this.$emit('input', val)
this.$emit('validateField') // 这句很重要
// 外层需要 每次 验证一下
// @validateField="$refs.yourRef.validateField('yourFiledName')"
}
},
getDiff (str1, str2) {
let ret = 0
for (let i = 0; i < str1.length; i++) {
if (str1.substr(i, 1) === str2.substr(i, 1)) {
// next
} else {
ret = i
break
}
}
return ret
},
clearSpot (vStr) {
// return vStr.replace(/[^0-9]/ig, '')
const restList = {
"数字": /[^0-9]/ig,
"中文数字字母_": /[^a-zA-Z0-9_\u4e00-\u9fa5]+$/ig,
}
return vStr.replace(restList[this.regStr], '')
}
},
created () { },
activated () { },
mounted () { },
beforeDestroy () { }
}
</script>
<style>
</style>
InputRegZen.vue 正则Input 限制输入框输入内容的更多相关文章
- 使用iScroll时,input等不能输入内容的解决方法
做移动平台的应用,使用iscroll使屏幕上下滑动.发现当使用iscroll后,input等不能输入内容了.只要在iscroll.js文件中加入如下代码就ok了. function allowForm ...
- 使用iScroll时,input等不能输入内容的解决方法(share)
最近做移动平台的应用,使用iscroll使屏幕上下滑动.发现当使用iscroll后,input等不能输入内容了.只要在iscroll.js文件中加入如下代码就ok了. function allowFo ...
- HTML中限制input 输入框输入内容
限制 input 输入框只能输入纯数字1.onkeyup = "value=value.replace(/[^\d]/g,'')" 使用 onkeyup 事件,有 bug ,那就是 ...
- input长度随输入内容动态变化 input光标定位在最右侧
<input type="text" onkeydown="this.onkeyup();" onkeyup="this.size=(this. ...
- 隐藏input光标和输入内容方法
text-indent: -999em; // 隐藏input文字margin-left: -100%;// 隐藏input光标
- input框监控输入内容
$(".input").bind("input porpertychange",function(){ console.log($(".input&q ...
- IE去掉input的type=”text”输入内容时出现的X和type=”password”出现的眼睛图标
从IE 10开始,type=”text” 的 input 在用户输入内容后,会自动产生一个小叉叉(X),方便用户点击清除已经输入的文本.对于type=”password”的 input 则会在右方显示 ...
- IE10去掉input的type=”text”输入内容时出现的小叉号(X)和type=”password”出现的小眼睛图标
最近在做一个后台管理系统项目,遇到以下两个问题: 1.从IE 10开始,type="text" 的 input 在用户输入内容后,会自动产生一个小叉号(X),方便用户点击清除已经输 ...
- vue4——把输入框的内容添加到页面(简单留言板)
文章地址:https://www.cnblogs.com/sandraryan/ vue最最最简单的demo(记得引入) 实例化一个vue,绑定#app的元素,要渲染的数组arr作为data. 把ar ...
- 项目小结:手机邮箱正则,URL各种判断返回页面,input输入框输入符合却获取不到问题
1.手机邮箱正则 近两年出来很多新号码,听说199什么的都有了- -导致以前的正则不能用了....这就很难过,总是过一段时间出一种新号码.因此,我决定使用返朴归真的手机正则. 手机正则:var reg ...
随机推荐
- 深度学习应用篇-元学习[15]:基于度量的元学习:SNAIL、RN、PN、MN
深度学习应用篇-元学习[15]:基于度量的元学习:SNAIL.RN.PN.MN 1.Simple Neural Attentive Learner(SNAIL) 元学习可以被定义为一种序列到序列的问题 ...
- 14.2 Socket 反向远程命令行
在本节,我们将继续深入探讨套接字通信技术,并介绍一种常见的用法,实现反向远程命令执行功能.对于安全从业者而言,经常需要在远程主机上执行命令并获取执行结果.本节将介绍如何利用 _popen() 函数来启 ...
- 构建Keepalived高可用集群
Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作 ...
- Libevent [补档-2023-08-29]
libevent的使用 8-1 安装 自己百度一下,安装它不是特别难,加油!!! 8-2 libevent介绍 它是一个开源库,用于处理网络和定时器等等事件.它提供了跨平台的API,能够在不同 ...
- css 修改复选框的样式
效果图: 实现代码如下: /* 选中input标签类型为复选框的 */ input[type="checkbox"] { width: 16px; height: 16px; ve ...
- Java-将Oracle中某个表的数据导出成数据文件
在做数据开发或者ETL工作中,经常会遇到需要在客户端将Oracle数据库中的某些表的数据导出,提供给其他人员使用的情况. 下面介绍我之前实施的一种方法:(该方法不是最好的办法,但是可以勉强使 ...
- ABC 333
ABCDE 赛时 AC. F 列方程:\(f_{i,j}\) 表示有 \(i\) 个人,第 \(j\) 个人最终活下来的概率. \(f_{i,1}=\dfrac{1}{2}f_{i,i}\),因为只有 ...
- 服务端渲染SSR的理解
服务端渲染SSR的理解 SSR服务端渲染Server Side Render就是当进行请求时,页面上的内容是通过服务端渲染生成的,浏览器直接显示服务端返回的HTML即可. 客户端渲染CSR 通常在构建 ...
- eclipse配置Maven本地仓库
一.首先下载maven插件并配置maven的环境变量,可参考:http://jingyan.baidu.com/article/cb5d61050b8ee7005d2fe04e.html 二.打开ec ...
- centos上使用makefile编译sliver时 提示gcc 错误,cannot find -ldl cannot find -lpthread cannot find -lc
github.com/bishopfox/sliver/server /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit ...