Date Format Verify
date format verify for production applications
Pattern Views
25,132
↗ 12.5%Last 30 days
Community Rating
⭐
96%
142 likes
Regular Expression
/^\d{4}-\d{2}-\d{2}$/
Explanation
This regex pattern validates date format verify. Commonly used by developers for input validation and form checking.
Code Examples
JavaScript Example
javascript
// date format verify - JavaScript
const regex = /^\d{4}-\d{2}-\d{2}$/;
function validate(input) {
if (!input || typeof input !== 'string') return false;
return regex.test(input.trim());
}
// Usage examples
console.log(validate('2023-12-25')); // true
console.log(validate('2023-13-25')); // falsePython Example
python
# date format verify - Python
import re
pattern = r"^\d{4}-\d{2}-\d{2}$"
regex = re.compile(pattern)
def validate(input_str):
if not input_str or not isinstance(input_str, str):
return False
return bool(regex.match(input_str.strip()))
# Usage examples
print(validate('2023-12-25')) # True
print(validate('2023-13-25')) # FalsePHP Example
php
<?php
// date format verify - PHP
function validate($input) {
if (!is_string($input) || empty(trim($input))) {
return false;
}
$pattern = '/^\d{4}-\d{2}-\d{2}$/';
return preg_match($pattern, trim($input)) === 1;
}
// Usage examples
var_dump(validate('2023-12-25')); // bool(true)
var_dump(validate('2023-13-25')); // bool(false)
?>Test Cases
✓ Should Match
2023-12-25
2024-01-01
✗ Should NOT Match
2023-13-25
invalid
Performance
Speed
medium
Memory
efficient