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

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

  1. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the message home a little bit, but other than that, this is great blog.

    A great read. I’ll certainly be back. http://droga5.net/

    Reply

Leave a Comment