Regex to Match a Decimal Number
Copy the pattern, paste your text below, and see every decimal it matches. Below the tester: how it handles signs, leading dots, and integers.
/
/
What this pattern matches
This matches decimal numbers with an optional sign, whether written as 3.14, 42, or .75.
How it works, part by part
[-+]? — an optional leading sign.
\d+\.?\d* — digits with an optional decimal point and more digits (covers 42 and 3.14).
|\.\d+ — or a leading-dot form like .75.
Strict validation
To validate a whole field as one number, anchor it with ^…$. As written it will find each number inside 1.2.3 separately rather than rejecting it.
FAQ
Does it match leading-dot numbers like .5?
Yes. The second alternative \.\d+ handles .5 and .75.
Does it accept a plus sign?
Yes. The optional [-+] leading sign matches both +42 and -0.5.
How do I reject 1.2.3?
Anchor the pattern with ^ and $ so the whole input must be a single valid number.