I want to check validation of my date in codeigniter. The date format will be yyyy-mm-dd. If someone type other way. I want to show error message. Please help.
1 Answer
CodeIgniter doesnt include date validation. You should validate manual like that:
$yourdate = '2015-03-09';
$pattern = '/^(19|20)\d\d[\-\/.](0[1-9]|1[012])[\-\/.](0[1-9]|[12][0-9]|3[01])$/';
if (!preg_match($pattern, $yourdate))
{
echo 'Your date does not match the YYYY-MM-DD format.';
}
else
{
echo 'Your date is correct!';
}
Demo: https://eval.in/297663