Languages
[Edit]
EN

JavaScript - how to check if a string only contains numbers?

8 points
Created by:
Kate_C
20380

Here you have simple RegExes that can used to check It:

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

Select one above pattern with function match.

Example:

// ONLINE-RUNNER:browser;

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

if (text.match(expression)) {
    console.log('I am number!');
}
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join