T
ToolPrime

Regex for Digits Only

Validates strings containing only numeric digits.

Pattern

/^\d+$/

Live Tester

Enter a string to test

Examples

12345
0
9876543210
12.34
-5
12 34

Pattern Breakdown

^\d+ — one or more digits from start

$ — to end (nothing else)

Code Snippets

Javascript

const regex = /^\d+$/;
regex.test("12345"); // true

Python

import re
bool(re.match(r"^\d+$", "12345"))  # True

Php

preg_match('/^\d+$/', "12345"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for Digits Only?
The regex pattern for Digits Only is /^\d+$/. Validates strings containing only numeric digits.
How do I use the Digits Only regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Digits Only pattern match?
It matches strings like 12345; it rejects strings like 12.34. See the Examples section above for the full list of matching and non-matching cases.

Related Tools