Check if String Contains Only Numbers Javascript

If you need to check a string contains only numbers, you need to use regex.

In this case isNaN() cannot be enough for solving this problem.

First Example
[js]
var first = "One is 1";
var second = "11";
console.log(/^\d+$/.test(first)); //Output: false
console.log(/^\d+$/.test(second)); // Output: true
[/js]

Second Example
[js]
var first = "One is 1";
var second = "11";
console.log(first.match(/^\d+$/)); //Output: null
console.log(second.match(/^\d+$/)); // Output: ["11"]
[/js]