<?php
if ($_SERVER['REQUEST_METHOD'] == ‘POST’ && isset($_POST['date'])) {
if (preg_match(‘#^(\d{4})-(\d{2})-(\d{2})$#’, $_POST['date'], $matches) && checkdate($matches[2], $matches[3], $matches[1])) {
echo ‘<p>The date is <strong>valid</strong>!</p>’;
}
else {
echo ‘<p>The date is <strong>invalid</strong>!</p>’;
}
echo ‘<hr>’;
}
?>
<form action=“<?php echo $_SERVER['PHP_SELF'] ?>“ method=“post”>
<label for=”date”>Enter an ISO 8601 date:</label>
<input type=“text” name=“date” id=“date”<?php if (!empty($_POST['date'])): ?> value=“<?php echo htmlentities($_POST['date']) ?>“<?php endif ?>>
<button type=“submit”>Check validity</button>
</form>

