Advertisement

Pattern library / Numbers & Codes

Regex to Match a Number in a Range (1 to 100)

Validating that a number falls inside a range is one of the most-asked regex questions (regex number between 1 and 100, scores 1-5, CIDR bits 1-32). Regex cannot compare values numerically, so a range is expressed as alternation over digit shapes: the short values, the mid values, and the exact upper bound — anchored, with no leading zeros and no decimals unless you want them.

The pattern
^(100|[1-9][0-9]?)$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
7Matchsingle digit in rangeTry →
42Matchtwo digits, no leading zeroTry →
100Matchexact upper bound via alternationTry →
0No matchrange starts at 1Try →
007No matchleading zeros rejectedTry →
101No matchabove the upper boundTry →
7.5No matchintegers only — decimals fail the $ anchorTry →

Where to use it

JavaScript (form validation)

const inRange = /^(100|[1-9][0-9]?)$/;
inRange.test('42');   // true
inRange.test('007');  // false
inRange.test('101');  // false

HTML input pattern attribute

<input type="text" inputmode="numeric"
       pattern="(100|[1-9][0-9]?)"
       title="Enter a number from 1 to 100">

SQL (BigQuery, RE2)

SELECT score FROM results
WHERE REGEXP_CONTAINS(CAST(score AS STRING), r'^(100|[1-9][0-9]?)$')

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

How do I match a number between 1 and 100 in regex?

Use ^(100|[1-9][0-9]?)$. It accepts 1-99 (no leading zeros) and the literal 100, and rejects 0, 007, 101 and 7.5.

Why can't I just write [1-100]?

Square brackets are a character class: they match exactly one character drawn from the set inside. [1-100] means 'one character that is 1, 0 or 0' — nothing to do with the number 100.

How do I allow decimals like 7.5?

Extend the pattern with an optional decimal part, e.g. ^(100|[1-9][0-9]?)(\.[0-9]{1,2})?$ for 0.00-100.99 style input, or handle the fraction in your range check instead.

Percentage Regex — Match Percent Values — Test & Copy · Extract Numbers from String — Regex + Examples · IPv4 CIDR Regex — Match IP/Prefix — Test & Copy

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.