Languages
[Edit]
EN

TypeScript - integer regular expression

0 points
Created by:
Paluskitten
356

In this short article, we would like to show how in a simple way check if the text is an integer number using regular expressions in TypeScript.

Quick solution:

const expression: RegExp = /^[+-]?\d+$/;

const isInteger = (text: string): boolean => !!text.match(expression);


// Usage example:

console.log(isInteger('123'));      // true
console.log(isInteger('-123'));     // true
console.log(isInteger('+123'));     // true
console.error(isInteger('3.14'));   // false
console.error(isInteger('abc'));    // false
console.error(isInteger('a123b'));  // false

See also

  1. JavaScript - integer regular expression

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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