Code Snippet: How to Quickly Check if a String is Not a Number

Here’s how to quickly check if a string value is a number or not:

var someString = "This is not a number",
    someNumber = "200";

if(isNaN(+someString) === true) {
    alert(someString + " is not a number");
} else {
    alert(someString + " is a number");
}

if(isNaN(+someNumber) === true) {
    alert(someNumber + " is not a number");
} else {
    alert(someNumber + " is a number");
}

Adding a + to the front of a string forces JavaScript to try and convert it into a number.