Date Format Pattern Php Example
date format pattern php example for production applications
Pattern Views
27,634
↗ 12.5%Last 30 days
Community Rating
⭐
96%
104 likes
Regular Expression
/^\d{4}-\d{2}-\d{2}$/
Explanation
This regex pattern validates date format pattern php example. Commonly used by developers for input validation and form checking.
Code Examples
JavaScript Example
javascript
// date format pattern php example - 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 pattern php example - 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 pattern php example - 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
optimized
Memory
low