I want to use a form input with type="number" and only allow numbers to be entered.
<input type="number" class="form-control fc-input"/>
I don't have a submit button, instead the value is checked after the input loses focus. However when you use type="number" and a non-number is entered, both the valueAsNumber and the value attributes of the input will be useless (NaN respectively ""). The problem with this is that I want to differentiate between the user entering an empty string (""), and the user entering a non-number value (e.g. 123abc). When the input is empty I want to execute function a, and if it's just a non-number I want to execute function b (otherwise do c).
Is there a good way to differentiate between NaN input and empty ("") input like this?
if(value === NaN)andif(value === "")?NaN === NaN // falseif(value === NaN)will always befalse, no matter whatvalueis. Nothing is===toNaN, includingNaN.