【问题标题】:Negative number in input type copy and paste reactive form输入类型复制和粘贴反应形式中的负数
【发布时间】:2019-01-08 05:58:16
【问题描述】:

目前使用reactive form,有些情况我们需要输入类型为数字,防止非负数,所以使用下面的方法

     <input type="number" class="form-control input-box" formControlName="test" required onkeypress="return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13) ? null : event.charCode >= 48 && event.charCode <= 57"  min="0"/>

它完全可以防止负数,但是如果有人复制并粘贴负数,它就会失败。 因此,每当有人复制并粘贴数字时,将其转换为正数并在控件中设置值

【问题讨论】:

标签: angular


【解决方案1】:

试试看

<input type="number" class="form-control input-box" formControlName="test" required/>

在您的组件中来自Group

'test': [, [Validators.max(Number.MAX_VALUE), Validators.min(0)]],

【讨论】:

    猜你喜欢
    • 2021-04-27
    • 2020-10-23
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多