Using a function to test the input value:
function isInvalidInput (val) {
return parseFloat(val) < 0.5 || isNaN(val);
}
console.log( isInvalidInput("-0.5") ); // true
console.log( isInvalidInput(-2) ); // true
console.log( isInvalidInput("1.2.5") ); // true
console.log( isInvalidInput("0.4") ); // true
console.log( isInvalidInput(0.4) ); // true
console.log( isInvalidInput("0.5") ); // false
console.log( isInvalidInput("1.2") ); // false
console.log( isInvalidInput("1000.9") ); // false
console.log( isInvalidInput(0.5) ); // false
console.log( isInvalidInput(0.999) ); // false
where parseFloat(val) < 0.5 (if necessary parses the string and) makes sure it's greater than 0.5 - disallowing negative values, and isNaN parses the string and checks if the format is a Number.
If the function raises atrue flag, the input is invalid.
If you want to invert the logic (like: isValidInput) than use return !( /*logic here*/ );
Using ES6 syntax:
const isInvalidInput = val => parseFloat(val) < 0.5 || isNaN(val);
let df = questionDuration.toString(); let length = df.replace(/[^.]/g, "").length; if(length >1){ return false; }99,9,9.9valid? Or is59the max value?