I'm trying to make a user registration. I just want to ask about the date using 3 inputs type="text" how to sanitize the Month, Day, and Year using PHP. If the month of February is a leap year or Month of November is only 30 days and the user input 31. Thanks guys!
if (isset($_POST['submit'])) {
$yy = preg_replace('#[^0-9]#i','',$_POST['yy']);
$mm = preg_replace('#[^0-9]#i','',$_POST['mm']);
$dd = preg_replace('#[^0-9]#i','',$_POST['dd']);
if ($mm > 12) {
$error[] = 'Invalid month.';
} else if ($dd > 31) {
$error[] = 'Invalid day.';
} else if (strlen($yy) < 4) {
$error[] = 'Invalid year.';
}
}