0

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 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.