Regex for Decimal Number
Matches positive and negative decimal numbers with a required fractional part.
Pattern
/^-?\d+\.\d+$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| -? | Optional minus sign |
| \d+ | One or more digits (whole part) |
| \. | Literal decimal point |
| \d+ | One or more digits (fractional part) |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| 3.14 | Match |
| -0.5 | Match |
| 100.00 | Match |
| 42 | No match |
| .5 | No match |
Common Use Cases
- Price validation
- Scientific data input
- Measurement values
Variations
^-?\d*\.?\d+$Optional decimal point (matches integers too)
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester