How to check for null or undefined number but handle the zero value?
How to check for null or undefined number but handle the zero value?
HTML
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color: red;">How to check for null or undefined number but handle the zero value?</h1>
<h3><a href="https://stackoverflow.com/q/75920528/2657515">https://stackoverflow.com/q/75920528/2657515</a></h3>
<br/>
<form onsubmit="return submitForm();">
<input id="input" value="0" />
<input type="submit" value="Check" />
</form>
<pre><span id="output"></span></pre>
<script type="">
<!--
function submitForm() {
var s = document.getElementById('input').value;
var outputText ="";
outputText += "<br/>Input is undefined/null/blank? <b>" + (isBlank(s) ? "Yes" : "No") + "</b>";
outputText += "<br/>Input is zero? <b>" + (isZero(s) ? "Yes" : "No") + "</b>";
document.getElementById('output').innerHTML = outputText;
document.getElementById('input').focus();
return false;
}
function isBlank(s) {
return (undefined == s || null == s || "" == s.trim());
}
function isZero(s) {
return (!isBlank(s) && "0" == s.trim());
}
document.getElementById('input').focus();
-->
</script>
</body>
</html>