Is there a way only allow a negative sign (or hyphen) for the first character in an input tag of type "number"? It has to be type "number" so that the correct keyboard appears on mobile. However, a user can still enter multiple negative signs before clicking "Submit". I have used .checkValidity(), which helps, but prevents entering a negative sign in the first place unless I type a number first. I can't validate with .value, since that returns a blank if it is invalid.
HTML
<input type="number" id="input">
JavaScript
var input = document.querySelector('#input');
var value;
input.oninput = function() {
if (input.checkValidity()) {
value = input.value;
}
else{
input.value = value;
}
}
Any help is appreciated. Thanks!