Languages
[Edit]
EN

JavaScript - check if string only contains numbers

14 points
Created by:
Kate_C
23510

Here you have simple RegExe's that can be used to check it:

  1. /^[0-9]+$/
  2. /^[0-9]{1,}$/
  3. /^\d+$/
  4. /^\d{1,}$/ 

Select one above pattern with String match() function.

Example:

// ONLINE-RUNNER:browser;

var expression = /^[0-9]+$/;
var text = '1000500100900';

if (text.match(expression)) {
    console.log('I am number!');
}

JavaScript - String (popular problems)

JavaScript - check if a string only contains numbers
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join