vue掩码处理

限制输入 (Restricted Input)

Allow restricted character sets in input elements.

在输入元素中允许使用受限制的字符集。

View Demo 查看演示 View Github 查看Github

特征 (Features)

  • Disallow arbitrary characters based on patterns

    禁止基于模式的任意字符

  • Maintains caret position

    保持插入符号位置

  • Format/Update on paste

    粘贴时格式化/更新

  • Works in IE11+

    可以在IE11 +中使用

发展历程 (Development)

Install dependencies

安装依赖

nvm use # if you have node version manager installed
npm i

Watch files and run demo server

观看文件并运行演示服务器

npm run development

This will start a server on port 3099 which can be overridden with the PORT env var.

这将在端口3099上启动服务器,该服务器可以被PORT env var覆盖。

Unit tests

单元测试

The following command will run the linting task and the unit tests.

以下命令将运行linting任务和单元测试。

npm test

Integration tests

整合测试

We use Browserstack to automate end to end testing on Google Chrome, Safari, Firefox, Microsoft Edge, and Internet Explorer 11.

我们使用Browserstack来自动化在Google Chrome,Safari,Firefox,Microsoft Edge和Internet Explorer 11上的端到端测试。

First, sign up for a free open source Browserstack account.

首先, 注册一个免费的开源Browserstack帐户 。

Copy the .env.example file to .env

.env.example文件复制到.env

cp .env.example .env

Fill in the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environmental variables with your credentials:

使用您的凭据填写BROWSERSTACK_USERNAME和BROWSERSTACK_ACCESS_KEY环境变量:

BROWSERSTACK_USERNAME=username
BROWSERSTACK_ACCESS_KEY=access_key

To run the integration tests in Safari, Google Chrome, Firefox, IE11 and Microsoft Edge:

要在Safari,Google Chrome,Firefox,IE11和Microsoft Edge中运行集成测试,请执行以下操作:

npm run development # in another terminal window
npm run test:integration

To run tests in only one browser, prefix the test command with an ONLY_BROWSERS env variable:

要仅在一个浏览器中运行测试,请在测试命令前添加ONLY_BROWSERS env变量:

# run only in edge browser
ONLY_BROWSERS=edge npm run test:integration# run only in chrome browser
ONLY_BROWSERS=chrome npm run test:integration# run only in ie 11 browser
ONLY_BROWSERS=ie npm run test:integration# run only in safari browser
ONLY_BROWSERS=safari npm run test:integration# run only in firefox browser
ONLY_BROWSERS=firefox npm run test:integration

To run tests in certain browsers, prefix the test command with an ONLY_BROWSERS env variable, with each browser comma separated:

要在某些浏览器中运行测试,请在测试命令前添加ONLY_BROWSERS env变量,并用逗号分隔每个浏览器:

# run only in edge and chrome browsers
ONLY_BROWSERS=edge,chrome npm run test:integration

To run only certain tests, add the .only property before running the test:

要仅运行某些测试,请在运行测试之前添加.only属性:

it.only('does something', function () {

用法 (Usage)

import RestrictedInput from 'restricted-input';const formattedCreditCardInput = new RestrictedInput({element: document.querySelector('#credit-card'),pattern: '{{9999}} {{9999}} {{9999}} {{9999}}'
});

模式 (Patterns)

Patterns are a mixture of Placeholders and PermaChars.

模式是PlaceholderPermaChar的混合。

占位符 (Placeholder)

A Placeholder is the part of the pattern that accepts user input based on some restrictions. A placeholder is defined in the pattern using two open curly brackets, the placeholder, followed by two closing curly brackets e.g. {{Abc123}}.

Placeholder是模式的一部分,它根据一些限制接受用户输入。 在模式中使用占位符定义两个占位符,占位符,后跟两个闭合花括号,例如{{Abc123}}

The patterns a Placeholder can be are:

Placeholder可以是的模式是:

  • a single alpha character that matches the alpha regex /[A-Za-z]/. e.g. {{C}} will match one alpha character.

    与alpha regex /[A-Za-z]/匹配的单个alpha字符。 例如{{C}}将匹配一个字母字符。

  • a single digit that matches the digit regex /[0-9]/. e.g. {{3}} will match one digit.

    与数字正则表达式/[0-9]/匹配的一个数字。 例如{{3}}将匹配一位数字。

  • a * character that matches /./. e.g. {{*}} will match the next character.

    /./匹配的*字符。 例如{{*}}将匹配下一个字符。

永久字符 (PermaChar)

A PermaChar is the part of the pattern that is automatically inserted. PermaChars are defined in the pattern as any characters other than Placeholders.

PermaChar是自动插入的模式的一部分。 PermaChar定义为除Placeholder的任何其他字符。

模式范例 (Example patterns)

Some example patterns with behavior are listed:

列出了一些具有行为的示例模式:

  • 12{{3}}

    12{{3}}

    • 12.12
    • Waits for a single digit from the user.等待用户的一位数字。
  • {{A}}BC

    {{A}}BC

    • Waits for a single alpha from the user.等待来自用户的单个Alpha。
    • BC.BC
  • ${{*2L}}E

    ${{*2L}}E

    • $.$
    • Waits for any single character input from the user.等待用户输入任何单个字符。
    • Waits for a single digit from the user.等待用户的一位数字。
    • Waits for a single alpha from the user.等待来自用户的单个Alpha。
    • E.E

粘贴事件 (Paste Event)

If an input is changed via a paste event, you may want to adjust the pattern before input formatting occurs. In this case, pass an onPasteEvent callback:

如果通过粘贴事件更改了输入,则可能需要在发生输入格式化之前调整模式。 在这种情况下,传递一个onPasteEvent回调:

const formattedCreditCardInput = new RestrictedInput({element: document.querySelector('#credit-card'),pattern: '{{9999}} {{9999}} {{9999}} {{9999}}',onPasteEvent: function (payload) {var value = payload.unformattedInputValue;if (requiresAmexPattern(value)) {formattedCreditCardInput.setPattern('{{9999}} {{999999}} {{99999}}')} else {formattedCreditCardInput.setPattern('{{9999}} {{9999}} {{9999}} {{9999}}')}})
});

API (API)

选项 (options)

Key Type Description
element HTMLInputElement or HTMLTextAreaElement A valid reference to an input or textarea DOM node
pattern String Pattern describing the allowed character set you wish for entry into corresponding field. See Patterns.
onPasteEvent Function (optional) A callback function to inspect the unformatted value of the input during a paste event. See Paste Event.
类型 描述
元件 HTMLInputElementHTMLTextAreaElement inputtextarea DOM节点的有效引用
模式 String 描述希望输入相应字段的允许字符集的模式。 参见模式 。
onPasteEvent Function (可选) 一个在粘贴事件期间检查输入的未格式化值的回调函数。 请参阅粘贴事件 。

浏览器支持 (Browser Support)

Desktop

桌面

  • Chrome (latest)

    镀Chrome(最新)

  • Firefox (17+)

    火狐(17+)

  • Safari (8+)

    Safari(8+)

  • IE11 (desktop/metro)

    IE11(台式机/地铁)

  • IE10 (desktop/metro)

    IE10(台式机/地铁)

  • IE9

    IE9

自动关闭格式的浏览器 (Browsers Where Formatting is Turned Off Automatically)

Old versions of Samsung Android browsers are incompatible with formatting. These will not attempt to intercept the values and format the input.

三星Android浏览器的旧版本与格式不兼容。 这些将不会尝试截取值并格式化输入。

去做 (TODO)

  • [ ] Improve jsdoc

    []改进jsdoc

  • [ ] Add example guides/pages

    []添加示例指南/页面

翻译自: https://vuejsexamples.com/input-mask-library-for-vue-js-based-on-restricted-input/

vue掩码处理

vue掩码处理_基于受限输入的vue.js输入掩码库相关推荐

  1. vue族谱架构_基于 Vue 实现动态家谱图/组织结构图

    Vue-Tree-Chart 最近一个项目里有个前端绘制家谱图的需求,大概是下面这个样子: 点击节点会弹出操作菜单,实现增删改查等操作,查阅网上资料发现,现有案例基本都是基于orgchart这个jQu ...

  2. vue事件总线_[面试] 聊聊你对 Vue.js 框架的理解

    作者:yacan8 https://github.com/yacan8/blog/issues/26 本文为一次前端技术分享的演讲稿,所以尽力不贴 Vue.js 的源码,因为贴代码在实际分享中,比较枯 ...

  3. vue key重复_得心应用的Vue高级技巧

    关注 Vue中文社区,回复"加群"加入我们一起学习,天天进步1,require.context()一个webpack的api,通过执行require.context函数获取一个特定 ...

  4. vue 初始化方法_前端发展方向指南—Vue源码初始化

    Vue 的源码结构比较绕,同时使用了大量的面向对象的高级技巧.重写方法,扩展方法,多态等应用.从 Vue 实例的加载过程就可以看出来,这一节重点看看 Vue 的源码加载流程是什么. 前言 vue已是目 ...

  5. vue音乐笔记_基于vue全家桶的移动端音乐web app

    项目描述 这是一个基于 Vue2.x 和网易云音乐 API制作的移动端 web app 项目:由于是出于练习和实验的目的,因此并非是网易云音乐 app 的替代品,目前也没有涵盖全部的功能: 该项目主要 ...

  6. seo vue 动态路由_基于vue.jsvue-router的动态更新TDK(SEO优化)

    本文基于工作项目开发,做的整理笔记 前几天帮朋友解决这个问题,顺带学习了一下,做个笔记Mark下. 前提条件: 你已经了解并使用vue,能够搭建应用站点. 编码环境: system:OS X EI C ...

  7. vue canvas插件_基于vue.js 制作在线桌椅定制选择交互特效源码

    码农那点事儿 关注我们,一起学习进步 基于vue.js写的在线桌子椅子垫子选择拼成的自己理想的书桌椅图像,这是一款交互式的课桌椅在线定制选择功能.非常不错,感兴趣的朋友前来下载使用. 下载源码(提取码 ...

  8. vue标签旋转_基于vue下input实现图片上传,压缩,拼接以及旋转的代码详解

    本篇文章给大家带来的内容是关于php队列的实现代码介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 作为一名前端工作人员,相信大家在开发系统的时候,经常有遇到需要这么一种需求,就是 ...

  9. vue部门结构图_基于 Vue 实现动态组织结构图

    基于 Vue 实现动态组织结构图 最近一个项目里有个前端绘制家谱图的需求, 大概是下面这个样子: 点击节点会弹出操作菜单, 实现增删改查等操作, 查阅网上资料发现, 现有案例基本都是基于 orgcha ...

最新文章

  1. Tomcat意外宕机分析
  2. 超图js版 iclient 基本开发 - 加载基本图层(以天地图示例)和基本地图控件
  3. 文件服务器定时开关机,如何配置作服务器定时开关机.ppt
  4. 【数据结构与算法-java实现】二 复杂度分析(下):最好、最坏、平均、均摊时间复杂度的概念
  5. STM32F103:一.(2)STLINK的配置
  6. 服务器开机显示密码过期,Windows server提示密码过期 更改密码使用期限方法
  7. 快速傅里叶变换MATLAB代码实现
  8. Kafka-3.0.1-Docker+集群 踩坑笔记
  9. qt 实现PDF阅读器 (一)
  10. cmd常用命令-快捷
  11. Costech A17T23SWB MTo
  12. lof基金溢价率php源码,一文读懂LOF基金套利策略 LOF是球友们很喜欢的一类基金,这类基金不仅可以在场内进行高效买卖,而且还可以进行折溢价套利。不过这里面牵扯到很多细节,... - 雪球...
  13. 数据库 流量切分_基于hash计算的多层实验流量切分的实现
  14. linux网站权限恢复,RMAN异机恢复——备份集权限问题
  15. GIS实验之加权泰森多边形的应用
  16. KiCad V6使用记录
  17. 【解决】移动用户如何使用APP自行取消全国亲情网业务
  18. ts:报错Could not find a declaration file for module xxx
  19. 计算机系统中的数据计量单位
  20. steam搬砖项目,怎么做?详细解答

热门文章

  1. 桑吉气泡图 -- KEGG富集气泡图升级版,5维展示富集结果
  2. AI生成假指纹以假乱真,你的指纹识别还安全吗?
  3. BDTC 2017 | 潜能无限,深度剖析大数据在交通旅游领域的应用实践
  4. 【转】散谈游戏保护那点事~就从_TP开始入手吧
  5. python爬b站番剧_Python爬取B站动漫番剧更新信息,附代码和讲解过程
  6. PHP合并数组及去重
  7. 计算机无法使用网络连接到服务器,Win7系统电脑玩英雄联盟无法连接到服务器的原因及解决办法(六种解决办法)...
  8. 如果你能看到,请转发,希望它能传遍中国
  9. 无论show在前还是在后plt.savefig图片保存到本地是空白
  10. tf.keras.losses.SparseCategoricalCrossentropy详解