JavaScript – Check if input is a number

I’m facing the following (basic) problem: I want to check if an input from an HTML-input field is not greater than 5 or not a number. If this is given the function should return true. Otherwise (so if greater than 5 or a number) it should resturn false. The validation if the number is not greater than 5 works fine so far but when I add the typeof-argument this one doesn’t works.
This is my code so far, thanks in advance!

function isValidStart(start) {
if (start.trim().length > 5 || typeof(start) === 'number') {
   return false
 return true

2 thoughts on “JavaScript – Check if input is a number”

  1. You can use the Number.isFinite() function to check if a variable is a finite number, which in your use case should do the Job.

    let intVar = 2;

Leave a Comment