Number regex pattern

Copy and test a JavaScript regex for numbers, with examples and a one-click link to the regex tester.

Number regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$

Flags: -

Search in text

Find matching fragments inside a larger block of text.

Regex: [+-]?(?:\d+(?:\.\d+)?|\.\d+)

Flags: g

Examples that match

  • 42
  • -17.5

Examples that do not match

  • twelve
  • 4.2.1