组件用.vue还是.js_Vue2.0组件使用RegExp来限制用户的输入

组件用.vue还是.js

Vue模式输入 (vue-pattern-input)

Works like native input element, you can add maxlength class attributes. You can use v-model too.

就像本机输入元素一样,您可以添加maxlength类属性。 您也可以使用v模型。

包含什么 (What's included)

Within the download you'll find the following directories and files, logically grouping common assets and providing both compiled and minified variations. You'll see something like this:

在下载文件中,您将找到以下目录和文件,对常用资产进行逻辑分组,并提供已编译和最小化的变体。 您会看到以下内容:

vue-pattern-input/
├── ...
├── src/
│   └── /component
│       └── pattern-input.vue // core
└── /view
    └── demo.html

参数声明 (Parameter declaration)

ParameterTypeDefaultRequiredDescription
regExpRegExpnullfalseUsing for: String.prototype.replace(regexp, replacement)
replacementString''falseUsing for: String.prototype.replace(regexp, replacement)
v-model[.number]String/NumbertrueUsing for getting input value
参数 类型 默认 需要 描述
regExp 正则表达式 空值 用于:String.prototype.replace(正则表达式,替换)
替代 '' 用于:String.prototype.replace(正则表达式,替换)
v模型[.number] 字符串/数字 真正 用于获取输入值

常用的regExp (Commonly used regExp)

regExpDescription
/[1]*|\D*/gpositive integer
/[^a-z]/glowercase
/[^A-Z]/guppercase
/[^\w]/g\w, Equivalent to [A-Za-z0-9_]
/[^\u4e00-\u9fa5]/gChinese
regExp 描述
/ [1] * | \ D * / g 正整数
/ [^ az] / g 小写
/ [^ AZ] / g 大写
/ [^ \ w] / g \ w,相当于[A-Za-z0-9_]
/ [^ \ u4e00- \ u9fa5] / g 中文

快速开始 (Quick start)

JavaScript (JavaScript)
setting: {
  regExp: /^[0\D]*|\D*/g, // Match any character that doesn't belong to the positive integer
  replacement: '',
  val: '223'
}
HTML (HTML)
<pattern-input class="your-class-name"
               :regExp="setting.regExp"
               :replacement="setting.replacement"
               @input="handleInput"
               @change="handleChange"
               v-model.number="setting.val"></pattern-input>

This setting will make user input positive integer only.

此设置将使用户仅输入正整数。

When you want get a Number, remember use v-model.number, and the safe maxlength is 15.

当您想要获取数字时,请记住使用v-model.number ,安全最大长度为15。



  1. 0\D ↩︎

    0 \ D↩︎

翻译自: https://vuejsexamples.com/a-vue2-0-component-used-regexp-to-limit-the-users-input/

组件用.vue还是.js

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值