oninput="this.value = this.value.replace(/[^-0-9.]/g, '')
I use this code in my project, but input also can get more than 1 minus sign like this:
---23
I want my input have this conditions:
- only can get positive and negative numbers
- zero or one minus
2
Answers
.replace(/^(-)+|[^d.]/g, '$1')
this is the right answer.
You can adjust your regex to below
EDIT.
Based on your requirements: