0

Currently using reactive form, there is situation where we need to use input type as number and prevent the non negtive number so using the following approach

     <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"/>

It perfectly work to prevent the negative number, however if some one is copy and paste the negative number it failed. So whenever any one copy and paste the number convert it to postive number and set the value in control

aryan
  • 105
  • 4
  • 15

1 Answers1

0

Just try

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

in your component fromGroup

'test': [, [Validators.max(Number.MAX_VALUE), Validators.min(0)]],
yala ramesh
  • 3,362
  • 1
  • 22
  • 35