EN
My tools

Number Regex Generator (Integer, Decimal, Thousands, Range)

Build a regex for integers, decimals, 1,234.56 or 1.234,56 separators, scientific notation, percentages or a numeric range like 1–255, then test it.

Regex
/^(?:[1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
JavaScript
Code
const ok = /^(?:[1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(value);
Matches
5
No match
4

[0-9] is used instead of \d so that only ASCII digits match in every language.

A regex compares text, not numbers, so a range is split into pieces: for 1–255 that is [1-9], [1-9][0-9], 1[0-9]{2}, 2[0-4][0-9] and 25[0-5].

Test results
LineValueResultNumber or reason
10No matchOutside 1–255
21Match1
399Match99
4100Match100
5199Match199
6255Match255
7256No matchOutside 1–255
8007No matchLeading zero
9-5No matchOutside 1–255
What the pattern checks
PartRule
range1 to 255 split into 5 parts whose digits can vary independently
My tools →
Advertisement

Numbers look simple, but a usable regex has to settle many details: is 007 allowed, may a value start with ".", is the thousands separator a comma (1,234.56), a dot (1.234,56) or a space, and how do you match only the numbers from 1 to 255? This generator builds the pattern from those choices, including the classic range-to-regex conversion, writes the code for JavaScript, PHP, Python, Java and C#, and tests it on your own values or pulls numbers out of text.

How to use this tool

  1. Choose the kind of number, or "Integer range" and enter from and to.
  2. Set the sign, decimal places and whether leading zeros or ".5" are allowed.
  3. Pick the language and validate or find.
  4. Test with your values and copy the regex.

Formula

integer: 0|[1-9][0-9]* · decimal: integer(\.[0-9]+)? · thousands: [1-9][0-9]{0,2}(,[0-9]{3})+ · range: split [min, max] at 9…9 and …0 boundaries

For a range, the interval is cut where digits roll over (9 → 10, 99 → 100 and at tens and hundreds of the upper limit), so that each piece can be written with fixed digits and character classes; negative ranges get a minus branch. Thousands patterns require complete groups of three digits (two for the Indian lakh/crore style) and also accept plain digits. In "find" mode a match may not touch other digits, so 1.2.3 and parts of longer numbers are skipped.

Example

For the range 1 to 255, the pattern is ^(?:[1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$. In the sample list 1, 99, 100, 199 and 255 match (5 matches); 0 and 256 are outside the range, 007 has leading zeros and −5 is negative. With "Thousands with commas", 1,234,567.89 matches but 1,23,456 does not, because each group after the first must have three digits.

Frequently asked questions

Why not just use \d+ and compare the number?

In code that is often better. A regex is useful where only a pattern is accepted — form validation attributes, configuration files, search tools, log filters.

Does the range pattern work with decimals?

No, it is for whole numbers. For decimal limits, match the number with the decimal pattern and compare the value in code.

Which separator style should I use?

English-speaking countries, Korea, Japan and China write 1,234.56; most of continental Europe and Latin America write 1.234,56; French and SI style use spaces; India groups 12,34,567.89.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Number Regex Generator (Integer, Decimal, Thousands, Range). https://kakao.mobile/tools/number-regex-tool/

MLA

“Number Regex Generator (Integer, Decimal, Thousands, Range).” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/number-regex-tool/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement