lisovaccaro lisovaccaro - 3 months ago 11
Javascript Question

Check if character is number?

I need to check whether

justPrices[i].substr(commapos+2,1)
.

The string is something like: "blabla,120"

In this case it would check whether '0' is a number. How can this be done?

Answer

Just use isNaN() to check if it is not a number:

if (!isNaN(parseInt(justPrices[i].substr(commapos + 2, 1), 10))) {
  // Is a number
}
Comments