经过几次尝试,我还没有找到解决方案,我想做一个面具。
这是我的问题:
我的面具组成:
- 需要 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”出现了。
你有什么建议可以让我找到解决方案吗?