Numbers
Decimal Number
Matches decimal numbers, including integers and negatives.
Try it in RegexProPattern
regexJavaScript
/^-?\d+(\.\d+)?$/Raw source: ^-?\d+(\.\d+)?$
How it works
`^-?\d+` matches optional sign and integer part. `(\.\d+)?` optionally matches a decimal point and fractional digits.
Examples
Input
3.14Matches
3.14
Input
-0.001Matches
-0.001
Input
42Matches
42
Common use cases
- Price input
- Scientific data
- Form validation
Related concepts
Character Classes: \d, \w, \s and Their Negations
ConceptShorthand character classes match broad categories of characters. \d is a digit, \w is a word character, \s is whitespace. Uppercase negates.
Custom Character Sets: [abc], [a-z], [^abc]
ConceptSquare brackets build a custom character class. [abc] matches any of a, b, or c. [a-z] is a range. A leading ^ negates the set.