Home > OS >  Preventing users to enter negative sign '-' in angular input field
Preventing users to enter negative sign '-' in angular input field

Time:11-27

is there a way to stop users from entering - sign in angular inputs?

Or clear the sign as soon as they entered it? I don't want values like -1, 9-, 124-5433.

CodePudding user response:

If you only want to accept numeric vaues you can add a min attribute to the html input, like

<input type="number" min="0">

So this won't let you insert negative values.

CodePudding user response:

You can try below way in your input field using oninput I hope it work for you

<input oninput="return event.target.value = event.target.value.replace(/[^0-9]/g,'')" type="text">
  • Related