I’m looking for a way to prevent a user entering negative numbers , but allow them to type floating numbers
- I’m using angular so angular tools also is a consideration
Thanks !
I’m looking for a way to prevent a user entering negative numbers , but allow them to type floating numbers
2
Answers
I did a directive recently for exactly that purpose. Consider improvements over it.
Then just
You can use a simple
javascript
function onkeypress
and detect when the user enters a-
and disable that.event.charCode != 45
detects and disables the user from typing a dash (-
).An alternative to prevent user from enter any type of text and just enable only number you can change the
type
of the input field tonumber
and add also themin
attribute as 0. You can also addstep
attribute to be decimal.