EN
TypeScript - check if string contains only numbers
0
points
In this article, we want to show how in TypeScript using simple regular expressions, check if string contains only numbers.
Example expressions:
/^[0-9]+$//^[0-9]{1,}$//^\d+$//^\d{1,}$/
As example, we can select first one, and do some test with match() function:
const expression: RegExp = /^[0-9]+$/;
const text: string = '1000500100900';
if (text.match(expression)) {
console.log('I am number!');
}