Regex for Date YYYY-MM-DD
Regex Pattern
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ISO 8601 date format
Quick Answer
The regex pattern for date yyyy-mm-dd is `^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`. ISO 8601 date format. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 2026-04-11 | ✓ Matches |
| 2000-01-01 | ✓ Matches |
| 1999-12-31 | ✓ Matches |
| 2026/04/11 | ✗ No match |
| 26-04-11 | ✗ No match |
| 2026-13-01 | ✗ No match |
| 2026-04-32 | ✗ No match |
Code Examples
javascript
const regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
const isValid = regex.test(value);python
import re
pattern = r'^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/', $value)) {
echo "valid";
}java
String pattern = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
Date DD/MM/YYYY
European date format with slashes
24-Hour Time
24-hour clock time in HH:MM format
12-Hour Time with AM/PM
12-hour clock with AM/PM
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
URL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs