Regex for Numbers and Dates
Integers, decimals, ISO dates, times, and versions.
- number regex
- date regex
- semver regex
- time regex
- validate number
Regex for Numbers and Dates
Integers, decimals, ISO dates, times, and versions.
Commands
| Command | What it does | |
|---|---|---|
^-?\d+$ | Integer with optional sign | |
^-?\d+(\.\d+)?$ | Decimal number | |
^\d{4}-\d{2}-\d{2}$ | ISO date shape | |
| `^([01]\d | 2[0-3]):[0-5]\d$` | 24h HH:MM |
^v?\d+\.\d+\.\d+$ | Semver-ish tag |
Example
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
FAQ
Shape check vs real validation?
Regex confirms shape only; parse with a date library to verify real calendars.
How do I allow thousands separators?
Match comma groups, then strip commas before numeric conversion.
よくある質問
Shape check vs real validation?
Regex confirms shape only; parse with a date library to verify real calendars.
How do I allow thousands separators?
Match comma groups, then strip commas before numeric conversion.