I used so many stuff but I am unable to validate date of birth should be less than 18 years old
<?php echo form_error('DOB'); ?>
<div class="form-group">
<label class="col-sm-3 control-label" for="form-field-3" >
Date Of Birth
</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="datepicker" name="DOB" placeholder="Date Of Birth" value="<?php echo set_value('DOB'); ?>" >
Alternatively, you could use a callback for this. Example:
public function your_form_page()
{
$this->load->library('form_validation');
// this part is when you set your validation rules
$this->form_validation->set_rules('DOM', 'Date of Birth', 'trim|required||callback_validate_age');
$this->form_validation->set_message('validate_age','Member is not valid!');
}
// you need to add this on the controller, this will be the custom validation
public function validate_age($age) {
$dob = new DateTime($age);
$now = new DateTime();
return ($now->diff($dob)->y > 18) ? false : true;
}