Giter Club home page Giter Club logo

vue-input-directive's Introduction

codepen地址

https://codepen.io/maiyaoqiang/pen/rNmVNXa?editors=1010

用法

已兼容vue3.0

npm install vue-input-directive --save
import Vue from 'vue'
import inputValidate from 'vue-input-directive'
Vue.use(inputValidate)

1.d-input-max

输入数字限制最大值

 <el-input v-d-input-max="99.99" v-model="value"></el-input>

2.d-input-int

只能输入正整数

 <el-input v-d-input-int v-model="value"></el-input>

3.d-input-point2

最多只能输入两位小数

 <el-input v-d-input-point2 v-model="value"></el-input>

4.d-input-en

只能输入英文

 <el-input v-d-input-en v-model="value"></el-input>

5.d-input-regexp

限制正则内容,输入时若正则部分匹配,则把匹配的部分留下,其余清空 实际上上面4种除了输入两位小数以外其他3个都可以用正则替代

<!-- 限制不能输入中文 -->
 <el-input v-d-input-regexp="/((?![\u4E00-\u9FA5]).)*/" v-model="value"></el-input>
<!-- 限制仅可输入数字字母 -->
 <el-input v-d-input-regexp="/[0-9A-Za-z]*/" v-model="value"></el-input>

6.混合使用

<!-- 限制输入两位小数 最大可输入99.99 -->
 <el-input 
  v-d-input-point2
  v-d-input-max="99.99"
  v-model="value"></el-input>

7.自定义正则

只能输入数字和字母和中文

import Vue from 'vue'
import {DInitFun} from 'vue-input-directive'
// 只能输入数字和字母
Vue.directive(
  'd-input-num-en',
  DInitFun((ele, binding) => {
      let value = ele.value + ''
      const reg = /[a-zA-Z0-9\u4E00-\u9FA5]*/
      const matchRes = value.match(reg)
      if (matchRes) {
        value = matchRes[0]
      } else {
        value = ''
      }
      ele.value = value
  })
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.