Developer Tools
Number Range Regex Generator
Generate a regular expression that matches every integer in a min to max range and rejects anything outside it. Supports negatives, leading zeros, and anchors.
Quick presets
Number range
Output options
Anchored is safest for whole-string validation. Grouped is best when you embed the pattern inside a larger regex. Bare drops the group so you can wrap it yourself.
Generated regex
^(?:[1-9]|[1-9][0-9]|100)$
Pattern length
26
Alternation branches
3
Anchor style
^...$
Test against a value
Match"42" matches the generated regex.
The test uses the anchor style you picked, so "Anchored" only matches a whole-string number, while "Bare" can match inside a longer string.
Common embeddings
JavaScript
const re = new RegExp("^(?:[1-9]|[1-9][0-9]|100)$");Python
re.compile(r"^(?:[1-9]|[1-9][0-9]|100)$")
HTML pattern attribute
<input pattern="(?:[1-9]|[1-9][0-9]|100)" />
Go (regexp)
regexp.MustCompile(`^(?:[1-9]|[1-9][0-9]|100)$`)
The HTML pattern attribute is automatically anchored to the whole value, so we strip the outer ^ and $ if present.
How the pattern was built
The range is split into blocks where every number shares the same regex shape. Each block becomes one alternative inside the final pattern.
Range breakdown
1 to 9
[1-9]Position 1 = 1-9, other positions fixed.
10 to 99
[1-9][0-9]Position 1 = 1-9, other positions fixed.
100
100Exact match: 100.
Notes on number range regex
Why not just \d+?
\d+ matches any sequence of digits, including ones that are outside your range. A correct number-range regex matches every integer inside the range and rejects everything outside it.
When to use anchors
Use ^...$ when validating a whole input, like an HTML form field. Drop the anchors when embedding inside a larger regex, for example matching a date or an IP octet.
Negative numbers
Negative numbers are added as separate alternatives prefixed with a literal -. If the range spans zero, the regex contains both negative and non-negative branches.
Leading zeros
Leading zeros are off by default because most form fields reject them. Enable the option to also match padded values like 007.
How to use
- Enter your minimum and maximum integers, or click one of the presets (1 to 100, 0 to 23, 1 to 12, port range, year range, and more) to load a common configuration.
- Pick an anchor style: Anchored (^...$) for whole-string form validation, Grouped ((?:...)) for embedding in a larger pattern, or Bare for hand-wrapping.
- Optionally tick Allow leading zeros so padded inputs like 0042 and 007 also match the regex.
- Copy the generated pattern, the /regex/ literal, or one of the language-specific snippets (JavaScript, Python, Go, HTML pattern attribute) for your stack.
- Type any value into the Test box to confirm the regex accepts or rejects it as expected before pasting the pattern into your code.
About this tool
Number Range Regex Generator builds a regular expression that matches every integer between a minimum and maximum and rejects everything outside the range. Writing this regex by hand is famously easy to get wrong: lazy shortcuts like \d{1,3} over-match (they let 999 slip through when you asked for 1 to 500), and naive alternations like (1|2|3|...|500) blow up the pattern. The tool runs the classic split-and-merge algorithm in your browser. It walks the range from the minimum upward, finds the longest contiguous block that fits the form prefix-plus-digit-class, emits one regex fragment per block, then merges adjacent fragments that differ in only one digit position so the final pattern is as compact as it can be. A range like 1 to 100 collapses to [1-9]|[1-9][0-9]|100 rather than a hundred-way alternation. The generator handles negatives by splitting the range into a negative branch (prefixed with a literal -) and a non-negative branch, so a span that crosses zero produces a single regex covering both signs without ever matching the bogus string "-0". Three anchor styles fit different needs: Anchored (^...$) for whole-string validation in HTML forms, Grouped ((?:...)) for embedding inside a larger regex like a date or an IP octet, and Bare for situations where you want to wrap the alternation yourself. An optional leading-zeros toggle accepts padded inputs such as 007 and 0042. Below the pattern, the tool shows the same expression copy-ready for JavaScript (new RegExp), Python (re.compile), Go (regexp.MustCompile), and the HTML pattern attribute (with the redundant ^ and $ stripped because the attribute is auto-anchored). A live test box runs the compiled regex against any value so you can confirm the match before pasting the pattern into your code. A range breakdown panel explains, block by block, what each alternative covers, so you can audit the regex against a spec instead of trusting it blindly. Everything runs locally in your browser; the min, max, and test values you enter are never uploaded.
Free to use. Works in your browser. No signup, no login.
Related tools
You may also like
Regex Tester
Live regex testing with highlights, capture groups, and replacement preview.
Open tool
DeveloperRegex Cheat Sheet
Searchable JavaScript regex reference with live examples and copy-ready patterns.
Open tool
DeveloperGlob Pattern Tester
Test glob patterns and negations against file paths with live results.
Open tool
DeveloperUUID Validator
Validate UUIDs, identify the version and variant, and decode v1, v6, and v7 timestamps.
Open tool
DeveloperEmail Validator
Validate, deduplicate, and clean lists of email addresses with typo suggestions.
Open tool
DeveloperCredit Card Validator
Luhn checksum, brand detection, length rules, and public test card numbers in your browser.
Open tool