Skip to main content
CalcHive

Regex for Integer

Matches positive and negative whole numbers (integers). No decimals, leading zeros allowed.

Pattern

/^-?\d+$/

Pattern Breakdown

TokenExplanation
^Start of string
-?Optional minus sign
\d+One or more digits
$End of string

Test Examples

InputMatch?
42Match
-100Match
0Match
3.14No match
abcNo match

Common Use Cases

  • Numeric input validation
  • Form field checking
  • Data type enforcement

Variations

^[1-9]\d*$

Positive integers without leading zeros

^(0|[1-9]\d*)$

Non-negative integers

Want to test this pattern with your own data?

Open the Regex Tester