regex - NGX MASK 选项的字母数字出现错误的位置
问题描述
经过几次尝试,我还没有找到解决方案,我想做一个面具。
这是我的问题:
我的面具组成:
- 需要 3 个数字
- 需要 1 个空间
- 需要 1 个字母数字
- 不需要 1 个字母
- 需要 1 个空间
- 需要 2 个数字
我的期望:
- 123 AA 12
- 123 12
- 123 1 12
- 123 12 12
在我的代码下方:
边.ts
fullName: string;
pattern = {
// tslint:disable-next-line: object-literal-key-quotes
W: {
pattern: new RegExp("[a-zA-Z]"), //uppercase and lowercase letters only
optional: true
},
K: {
pattern: new RegExp("[a-zA-Z0-9]"), //uppercase and lowercase alphanumerics only but optionnal
optional: true
},
X: {
pattern: new RegExp("[0-9]") // numerics only
},
E: {
pattern: new RegExp("[ ]"), //space only but optionnal
optional: true
}
};
边.html
<input
mask="XXX KWEXX"
[(ngModel)]="fullName"
[patterns]="pattern"
[dropSpecialCharacters]="false"
/>
<p>format : XXX KW AA</p>
<br /><br />
<p>{{ fullName }}</p>
当我写 123 AA 12 一切都很好,
当我写 123 A 12 时,“1”消失了,“2”出现了。
你有什么建议可以让我找到解决方案吗?
解决方案
推荐阅读
- google-analytics - Measurement Protocol 仅在我提供 cid 时跟踪(当我仅提供 uid 时不跟踪)
- python - pdfkit 图像未使用 Django 嵌入
- python - 安装 AssimpCy
- reactjs - React,使用 react-hook-form 提交表单后显示消息
- debugging - 在 IntelliJ 中停止/终止调试线程
- angular - 如果我的内容溢出窗口高度,Angular 如何在底部自动滚动到新添加的元素?适用于整个页面,app
- c - 从单链表中删除元素的一个非常意外的问题
- php - Laravel SHOW WARNINGS 给出无缓冲查询活动错误
- javascript - 如何创建下拉文本的垂直列表?
- java - powerMockito 中的空指针异常