ngx-mask 不允许货币输入为负值

Ash*_*yan 4 angular ngx-mask

我需要阻止负值的类型,并且不允许99,999,999.99输入比我输入更多的数字。

这是我用于货币输入的代码。

<input mask="separator.2" thousandSeparator="," placeholder="Currency">
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

这里也是 Stackblitz 的例子。

https://stackblitz.com/edit/ngx-mask-currency-input?file=src/app/app.component.html

更新

我找到了问题第二部分的答案。现在输入看起来像这样

<input mask="separator.2" thousandSeparator="," separatorLimit="10000000"  placeholder="Currency">
Run Code Online (Sandbox Code Playgroud)

现在只需要屏蔽-字符的类型

pc_*_*der 5

你可以用keypress事件解决的演示

<input (paste)="onPaste($event)" mask="separator.2" thousandSeparator=","  separatorLimit="10000000" [allowNegativeNumbers]="false" placeholder="Currency" class="form-control" (keypress)="isPositive($event)">
Run Code Online (Sandbox Code Playgroud)

在组件中

  isPositive(event: any) { return event.key === '-' ? false : true; }
Run Code Online (Sandbox Code Playgroud)

和块粘贴

 onPaste(event){
    event.preventDefault();
  }
Run Code Online (Sandbox Code Playgroud)