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:
xxxxxxxxxx
1
const expression: RegExp = /^[0-9]+$/;
2
const text: string = '1000500100900';
3
4
if (text.match(expression)) {
5
console.log('I am number!');
6
}