I have a input that i want to recive any number (dont matter if its negative, float, long) i code this to now allow null, undefined or empty values, but if I enter 0 it is read as empty
const inputElement = Number(document.getElementById("inputNumber").value);
if (!inputElement) {
window.alert("Insira um valor válido");
return;
}
i already tried this but dont work
if (!inputElement && inputElement != 0){
window.alert("Insira um valor válido");
return;
}
Does anyone know how to differentiate 0 from empty or vice versa?
i already tried this but nothing changed
- odd, seeing as that actually does what you'd expect - of course, I may be misunderstanding what you want ... andNumber("")
is zero of course - perhaps you should checkdocument.getElementById("inputNumber").value.length
to see if it's emptyNumber("")
IS zero - you'll want to check the length of the actual input of course!inputElement && inputElement != 0
should be!inputElement || Number(inputElement) == 0