首页 > 解决方案 > NGX MASK 选项的字母数字出现错误的位置

问题描述

经过几次尝试,我还没有找到解决方案,我想做一个面具。

这是我的问题:

我的面具组成:

我的期望:

在我的代码下方:

边.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”出现了。

你有什么建议可以让我找到解决方案吗?

标签: regexangularmaskngx-mask

解决方案


推荐阅读