我使用 ngx-mask 14.2.4。我想为我的邮政编码输入字段允许以下条件:
我尝试过:
<input
type="text"
[mask]="mask"
[patterns]="customPatterns"
[specialCharacters]="['-']"
[showMaskTyped]="true"
[dropSpecialCharacters]="false"/>
和
this.mask = '0{12}';
this.customPatterns = { '0': { pattern: new RegExp('\[A-Za-z0-9- \]')} };
但是没有成功。它不允许我输入特殊字符(空格和 - )。如何达到目标?
像这样更改 Html 中的输入标签,
[specialCharacters]="['-', ' ']" <!-- Added space -->
并像这样更改你的 ts 文件,
mask = 'A{2,12}'; // Adjust the pattern to allow between 2 and 12 characters
customPatterns = { A: { pattern: new RegExp('[A-Za-z0-9- ]') } }; // Allow letters, numbers, hyphens, and spaces